-
Notifications
You must be signed in to change notification settings - Fork 0
Compliant token #4
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
0xpApaSmURf
wants to merge
68
commits into
main
Choose a base branch
from
feat/cToken
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
68 commits
Select commit
Hold shift + click to select a range
81b2dff
initial project creation boilerplate
0xpApaSmURf cac5e89
removed backend component
0xpApaSmURf d270a86
rename hardhat -> contracts, added cERC20 contract and mockHBT
0xpApaSmURf 91ef6b9
added wrap and unwrap functionalities to cERC20
0xpApaSmURf b059229
updated scripts,hardhat config and gitignore
0xpApaSmURf d9476e6
updated typechain types, gitignore
0xpApaSmURf 5b6ac0a
hbt claiming flow on home page complete, home page content included, …
0xpApaSmURf b23d167
added cerc20 balance hook, added balance and claim HBT components
0xpApaSmURf c6416f4
updated landing page
0xpApaSmURf 38f613b
working mint page for cerc20 tokens
0xpApaSmURf 16f3d7b
modified cERC20 token to allow minting from non-contract owner
0xpApaSmURf f69923e
updated frontend typechain types
0xpApaSmURf 928c570
added refresh context for auto-refreshing hooks
0xpApaSmURf e5c8693
using refresh context
0xpApaSmURf 1b6ddb1
swap page now works
0xpApaSmURf 35e20e3
minor styles additions
0xpApaSmURf 105cda0
updated scripts to deploy mock erc20 instead
0xpApaSmURf c3c01b2
wrapping and unwrapping now works
0xpApaSmURf f63ab13
renamed folder contracts -> hardhat for consistency
0xpApaSmURf 549fd50
updated README, hardhat config, minor component updates
0xpApaSmURf a9e5a95
renamed useHBT hook -> useHasHBT, added some comments
0xpApaSmURf db499ed
some fixes
0xpApaSmURf d8f658d
updated import
0xpApaSmURf 8942c32
updated import for usehashbt
0xpApaSmURf d739bf9
changed swap -> send
0xpApaSmURf 554c240
removed DS_Store
0xpApaSmURf 164ee34
removed typechain types from frontend
0xpApaSmURf 12cd802
removed .yarn
0xpApaSmURf a89bc49
removed typechain types from hardhat folder
0xpApaSmURf 7db8aef
added premint for smooth unwraps
0xpApaSmURf 7fb1985
removed .yarnrc.yml
0xpApaSmURf 4cc4a22
added comments to contract
0xpApaSmURf d63c0bb
simplfied hardhat config
0xpApaSmURf e64c3ee
changed typechain types folder due to copying issues
0xpApaSmURf 0cb47d1
removed typechain artifacts again
0xpApaSmURf 094759b
updated default hardhat node chainId
0xpApaSmURf 97a74a1
updated default contract addresses
0xpApaSmURf 6daccfa
fixed script that deploys and prewraps ERC20
0xpApaSmURf b087444
updated default cERC20 deployment address
0xpApaSmURf 917b635
standardised localhost chainId to 1337
0xpApaSmURf 43ea625
added toasts for error display
0xpApaSmURf 4fca027
added error toast for failed wallet connection
0xpApaSmURf f86032b
placed full tx flow in try/catch
0xpApaSmURf 74057a1
Fixed trade -> transfer on send page
0xpApaSmURf 20d5720
updated and fixed tasks
0xpApaSmURf ec519a4
removed artifact of copied utils from the airdrop example
0xpApaSmURf 40226fa
removed reference to claimingperiod
0xpApaSmURf bbe5b14
refactored getContract methods
0xpApaSmURf fec117b
fixed typo
0xpApaSmURf 574f928
added clarity on where typchain artifacts end up
0xpApaSmURf a7639ce
updated package.json and added license and copyright files
0xpApaSmURf bf11d0b
migrated to rainbowkit and wagmi from web3context
0xpApaSmURf 9bc5b1f
removed web3contextprovider, updated gitignore for typechain types
0xpApaSmURf 1e28207
Removed Kovan from supported networks
0xpApaSmURf a0a086e
Updated contract addresses for supported networks
0xpApaSmURf 31c8839
Fixed bug where view modifiers caused HBT to fail
0xpApaSmURf 39a7be1
Changed to GPLv3 license header
0xpApaSmURf f4d39a0
Updated package.json, typescript version to 4.7.4
0xpApaSmURf fa11dfd
Added optional hardhat accounts
0xpApaSmURf 314eafe
updated main build script to perform it non-concurrently
0xpApaSmURf 32c415b
uses SPDX license identifier in package.json
0xpApaSmURf 96bcfb4
fixed build script
0xpApaSmURf 3ea1b7f
add next as dev dependency for vercel
0xpApaSmURf f502177
claim hbt button now redirects to sandbox for nonlocal
0xpApaSmURf 60a8c2b
claim erc20 button now links to faucet when not on localhost
0xpApaSmURf 88b8480
fixed balances to use correct 18 decimals for display and transactions
0xpApaSmURf 60d5eae
fixed number overflow on send page
0xpApaSmURf a9ae2f5
added footer with disclaimer and contract address
0xpApaSmURf 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,33 @@ | ||
| # dependencies | ||
| node_modules | ||
| /shared/node_modules | ||
| /.pnp | ||
| .pnp.js | ||
|
|
||
| # production | ||
| /build | ||
|
|
||
| # misc | ||
| .DS_Store | ||
| *.pem | ||
|
|
||
| # debug | ||
| npm-debug.log* | ||
| yarn-debug.log* | ||
| yarn-error.log* | ||
|
|
||
| # local env files | ||
| .env | ||
| .env.local | ||
| .env.development.local | ||
| .env.test.local | ||
| .env.production.local | ||
|
|
||
| # Zero-Installs (Yarn v2) | ||
| .yarn/* | ||
| !.yarn/cache | ||
| !.yarn/patches | ||
| !.yarn/plugins | ||
| !.yarn/releases | ||
| !.yarn/sdks | ||
| !.yarn/versions |
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,8 @@ | ||
| Copyright 2022 DeFi Labs GmbH | ||
|
|
||
| This file is part of the Multi-network Faucet demo app leveraging Humanbound Tokens (hereinafter “Multi-network Faucet”). | ||
| The Multi-network Faucet demo is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License or any later version. | ||
|
|
||
| The Multi-network Faucet demo is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. | ||
|
|
||
| You should have received [a copy of the GNU General Public License](./LICENSE) along with Multi-network Faucet. If not, see <https://www.gnu.org/licenses/>.” |
Large diffs are not rendered by default.
Oops, something went wrong.
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,149 @@ | ||
| # cERC20: Compliant ERC20 Token | ||
|
|
||
| This is a proof of concept of an Compliant ERC20 (cERC20) token made possible through the use of Humanbound where users must be verified to be compliant and issued a Humanbound token before being able to transact with a cERC20 token. | ||
|
|
||
| The cERC20 token demonstrates 2 main implementation flows: | ||
|
|
||
| - Minting/burning | ||
| - Wrapping/Unwrapping | ||
|
|
||
| Minting/burning follows the traditional token lifecycle where tokens are created and destroyed directly to and from wallets by the contract administrator. This is the simplest method for creating and destroying cERC20 tokens. | ||
|
|
||
| Wrapping/unwrapping is a new feature made possible by cERC20. Many popular tokens already exist in the permissionless space, but are without the guarantees of being compliant. Thus it may be dangerous from a regulatory standpoint for some players to be seen transacting using these tokens. By wrapping tokens, you are able to take a token like USDC, and convert it to cUSDC through verified Humanbound users, and transact it with guarantees that the flow of the token will and always has passed through clean hands. | ||
|
|
||
| ## Notes | ||
|
|
||
| - The smart contract `cERC20.sol` implements both flows in the same contract, but in practice we recommend that only one of them is used to simplify the management of the contract. | ||
| - In practice, the `cERC20.sol` contract would point to the production Humanbound smart contracts, but for testing it would point to your dummy local deployment. | ||
| - We used a dummy ERC20 token to demonstrate wrapping and unwrapping flows. This in practice would be used to create compliant versions of existing tokens such as USDC or DAI. | ||
|
|
||
| # Testing locally | ||
|
|
||
| ## Requirements | ||
|
|
||
| It's required that you have `yarn` installed. If you don't, simply run `npm i -g yarn`. | ||
|
|
||
| <br/> | ||
|
|
||
| ## Setup | ||
|
|
||
| At the root of the project, install all the dependencies: | ||
|
|
||
| ``` | ||
| yarn install | ||
| ``` | ||
|
|
||
| Let’s make sure the types generated by typechain (smart contract typing) are copied to the frontend. Inside the `hardhat` folder, run: | ||
0xpApaSmURf marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| ```solidity | ||
| yarn run typechain | ||
| ``` | ||
|
|
||
| They should be copied to the `frontend/lib` folder. | ||
|
|
||
| Then, you can run the frontend, and local blockchain node all from 1 single terminal instance. | ||
| To do so, run the following command from the project's root directory. | ||
|
|
||
| ```bash | ||
| yarn dev | ||
| ``` | ||
|
|
||
| This uses a package called `concurrently` that allows you to concurrently run all instances from a single terminal. | ||
|
|
||
| Once the app is running, you can view at: | ||
|
|
||
| - Frontend [http://localhost:3000](http://localhost:3000/) | ||
|
|
||
| It also starts a [local network with Hardhat](https://hardhat.org/hardhat-network/docs/overview). You can connect to it via Metamask using this RPC url: [`http://127.0.0.1:8545`](http://127.0.0.1:8545/) | ||
|
|
||
| You'll need funds for your address to interact with the smart contracts locally, so in the `hardhat` folder run: | ||
|
|
||
| ```bash | ||
| npx hardhat --network localhost fund --to <your-address> | ||
| ``` | ||
|
|
||
| Now in the same folder, deploy the mock Humanbound Token contract by running: | ||
|
|
||
| ```bash | ||
| npx hardhat run --network localhost scripts/deployHBT.ts | ||
| ``` | ||
|
|
||
| Next deploy the mock ERC20 Token contract by running: | ||
|
|
||
| ```bash | ||
| npx hardhat run --network localhost scripts/deployERC20.ts | ||
| ``` | ||
|
|
||
| Both deployments will print out the address of the deployed contracts. Populate the variables in `scripts/deploycERC20.ts` with these addresses and then deploy the `cERC20` token with: | ||
|
|
||
| ```bash | ||
| npx hardhat run --network localhost scripts/deploycERC20.ts | ||
| ``` | ||
|
|
||
| Now populate the contract address config in `frontend/src/shared/config/contracts.ts` for `Web3ChainReference.EIP155_HARDHAT_LOCAL` for all three contracts. | ||
|
|
||
| We’re ready to go! 🚀 | ||
|
|
||
| ## Step 1: Claiming a HBT | ||
|
|
||
| Before being able to interact with anything, you will need to mint yourself a mock HBT. | ||
|
|
||
| Note: In practice, you would use the real HBT contract but for demonstration purposes, we'll be using the MockHBT that you deployed earlier. | ||
|
|
||
| Go to the home page [http://localhost:3000/](http://localhost:3000/) to mint yourself a “mock HBT”. | ||
|
|
||
| Once minted, the frontend should inform you that you now own a HBT. | ||
|
|
||
| ## Step 2: Obtaining some cERC20 | ||
|
|
||
| ### Minting | ||
|
|
||
| Now armed with your HBT, you'll be able to get some cERC20! You can try this before you've minted a HBT and you'll find that you are unable to as only HBT holders can gain access to cERC20. | ||
|
|
||
| Go to the mint page [http://localhost:3000/mint](http://localhost:3000/mint) to mint some cERC20 tokens. Each mint drips you 10 CERC. | ||
|
|
||
| Now you can play around with the cERC20 tokens! | ||
|
|
||
| ### Wrapping | ||
|
|
||
| An alternative method for obtaining cERC20 is by 'wrapping' a normal ERC20 token. | ||
|
|
||
| Go to the wrap page [http://localhost:3000/wrap](http://localhost:3000/wrap). | ||
|
|
||
| First we will obtain some ERC20 tokens by clicking "Claim". This will drip you 10 ERC20 tokens. | ||
|
|
||
| Next we will convert this ERC20 into compliant cERC20 by inserting "10" in the box and clicking "Wrap ERC20". This will wrap 10 of your non-compliant tokens and turn them into cERC20! | ||
|
|
||
| Once you're done with cERC20 and you want them back in ERC20 to trade them on permissionless DeFi, simply "Unwrap" the desired amount of cERC20 tokens and they will be converted back to ERC20. | ||
|
|
||
| ## Step 3: Trading your cERC20 | ||
|
|
||
| Next we will send some cERC20 tokens. | ||
|
|
||
| Note: Your trade recipient must also be a HBT owner or your trade will fail! | ||
|
|
||
| Go to the send page [http://localhost:3000/send](http://localhost:3000/send). | ||
|
|
||
| This page allows you to send some tokens to a recipient, this can be easily implemented by exchanges to allow swaps between different cERC20 tokens such as cUSDC or cDAI. | ||
|
|
||
| Simply input the recipient address and the amount of cERC20 you wish to send, and click "Transfer". | ||
|
|
||
| You will have successfully transferred some tokens! | ||
|
|
||
| ## Troubleshooting | ||
|
|
||
| - Balances appearing incorrect | ||
|
|
||
| ⇒ Try refreshing the page | ||
|
|
||
| - "Received invalid block tag X. Latest block number is Y” | ||
|
|
||
| ⇒ Switch network with your wallet and switch back to the local network. See [this answer](https://ethereum.stackexchange.com/a/112214). | ||
|
|
||
| - Issue with nonces | ||
|
|
||
| ⇒ Enable custom nonces in Metamask and manually enter the right nonce value when submitting a transaction. | ||
|
|
||
| # Credits | ||
|
|
||
| - [create-ether-dapp](https://github.com/adriandelgg/create-ether-dapp) | ||
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": ["plugin:react/recommended", "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,46 @@ | ||
| # dependencies | ||
| /node_modules | ||
| /.pnp | ||
| .pnp.js | ||
|
|
||
| # testing | ||
| /coverage | ||
|
|
||
| # next.js | ||
| /.next/ | ||
| /out/ | ||
|
|
||
| # production | ||
| /build | ||
|
|
||
| # typechain types | ||
| lib | ||
|
|
||
| # misc | ||
| .DS_Store | ||
| *.pem | ||
|
|
||
| # debug | ||
| npm-debug.log* | ||
| yarn-debug.log* | ||
| yarn-error.log* | ||
| tsconfig.tsbuildinfo | ||
|
|
||
| # local env files | ||
| .env | ||
| .env.local | ||
| .env.development.local | ||
| .env.test.local | ||
| .env.production.local | ||
|
|
||
| # vercel | ||
| .vercel | ||
|
|
||
| # Zero-Installs (Yarn v2) | ||
| .yarn/* | ||
| !.yarn/cache | ||
| !.yarn/patches | ||
| !.yarn/plugins | ||
| !.yarn/releases | ||
| !.yarn/sdks | ||
| !.yarn/versions |
Empty file.
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 @@ | ||
| /// <reference types="next" /> | ||
| /// <reference types="next/image-types/global" /> | ||
|
|
||
| // NOTE: This file should not be edited | ||
| // see https://nextjs.org/docs/basic-features/typescript for more information. |
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,7 @@ | ||
| /** @type {import('next').NextConfig} */ | ||
| module.exports = { | ||
| reactStrictMode: true, | ||
| images: { | ||
| domains: ['ipfs.io'] | ||
| } | ||
| }; |
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,40 @@ | ||
| { | ||
| "name": "frontend", | ||
| "license": "GPL-3.0", | ||
| "author": "Violet", | ||
| "scripts": { | ||
| "dev": "next dev", | ||
| "build": "next build", | ||
| "start": "next start", | ||
| "lint": "next lint" | ||
| }, | ||
| "dependencies": { | ||
| "@rainbow-me/rainbowkit": "^0.8.0", | ||
| "axios": "^0.25.0", | ||
| "dotenv": "^14.2.0", | ||
| "ethers": "^5.4.6", | ||
| "ipfs-http-client": "^55.0.0", | ||
| "next": "12.0.8", | ||
| "react": "17.0.2", | ||
| "react-dom": "17.0.2", | ||
| "react-loader-spinner": "^5.0.9", | ||
| "react-toastify": "^8.0.3", | ||
| "react-toggle-dark-mode": "^1.0.4", | ||
| "wagmi": "^0.8.6" | ||
| }, | ||
| "devDependencies": { | ||
| "@tailwindcss/typography": "^0.5.0", | ||
| "@types/lodash": "^4.14.175", | ||
| "@types/node": "^17.0.8", | ||
| "@types/react": "17.0.38", | ||
| "@types/react-dom": "^17.0.9", | ||
| "autoprefixer": "^10.3.4", | ||
| "eslint": "8.7.0", | ||
| "eslint-config-next": "12.0.8", | ||
| "eslint-plugin-react-hooks": "^4.2.0", | ||
| "postcss": "^8.3.6", | ||
| "tailwindcss": "^3.0.11", | ||
| "ts-node": "^10.2.1", | ||
| "typescript": "4.7.4" | ||
| } | ||
| } |
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 @@ | ||
| import type { AppProps } from "next/app"; | ||
| import "styles/globals.css"; | ||
| import "react-loader-spinner/dist/loader/css/react-spinner-loader.css"; | ||
| import "react-toastify/dist/ReactToastify.css"; | ||
| import { RainbowKitProvider, darkTheme } from "@rainbow-me/rainbowkit"; | ||
| import "@rainbow-me/rainbowkit/styles.css"; | ||
|
|
||
| import { WagmiConfig } from "wagmi"; | ||
| import Layout from "src/context/Layout"; | ||
| import { RefreshContextProvider } from "src/context/RefreshContext"; | ||
| import { chains, wagmiClient } from "src/utils/wagmi"; | ||
|
|
||
| function MyApp({ Component, pageProps }: AppProps) { | ||
| return ( | ||
| <WagmiConfig client={wagmiClient}> | ||
| <RainbowKitProvider | ||
| chains={chains} | ||
| modalSize="compact" | ||
| theme={darkTheme({ | ||
| accentColor: "#A73CFD", | ||
| })} | ||
| > | ||
| <RefreshContextProvider> | ||
| <Layout> | ||
| <Component {...pageProps} /> | ||
| </Layout> | ||
| </RefreshContextProvider> | ||
| </RainbowKitProvider> | ||
| </WagmiConfig> | ||
| ); | ||
| } | ||
|
|
||
| export default MyApp; |
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.
Uh oh!
There was an error while loading. Please reload this page.