Skip to content
Open
Show file tree
Hide file tree
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 Nov 10, 2022
cac5e89
removed backend component
0xpApaSmURf Nov 10, 2022
d270a86
rename hardhat -> contracts, added cERC20 contract and mockHBT
0xpApaSmURf Nov 10, 2022
91ef6b9
added wrap and unwrap functionalities to cERC20
0xpApaSmURf Nov 11, 2022
b059229
updated scripts,hardhat config and gitignore
0xpApaSmURf Nov 11, 2022
d9476e6
updated typechain types, gitignore
0xpApaSmURf Nov 14, 2022
5b6ac0a
hbt claiming flow on home page complete, home page content included, …
0xpApaSmURf Nov 14, 2022
b23d167
added cerc20 balance hook, added balance and claim HBT components
0xpApaSmURf Nov 15, 2022
c6416f4
updated landing page
0xpApaSmURf Nov 15, 2022
38f613b
working mint page for cerc20 tokens
0xpApaSmURf Nov 15, 2022
16f3d7b
modified cERC20 token to allow minting from non-contract owner
0xpApaSmURf Nov 15, 2022
f69923e
updated frontend typechain types
0xpApaSmURf Nov 15, 2022
928c570
added refresh context for auto-refreshing hooks
0xpApaSmURf Nov 15, 2022
e5c8693
using refresh context
0xpApaSmURf Nov 15, 2022
1b6ddb1
swap page now works
0xpApaSmURf Nov 15, 2022
35e20e3
minor styles additions
0xpApaSmURf Nov 15, 2022
105cda0
updated scripts to deploy mock erc20 instead
0xpApaSmURf Nov 15, 2022
c3c01b2
wrapping and unwrapping now works
0xpApaSmURf Nov 15, 2022
f63ab13
renamed folder contracts -> hardhat for consistency
0xpApaSmURf Nov 16, 2022
549fd50
updated README, hardhat config, minor component updates
0xpApaSmURf Nov 16, 2022
a9e5a95
renamed useHBT hook -> useHasHBT, added some comments
0xpApaSmURf Nov 17, 2022
db499ed
some fixes
0xpApaSmURf Nov 17, 2022
d8f658d
updated import
0xpApaSmURf Nov 17, 2022
8942c32
updated import for usehashbt
0xpApaSmURf Nov 17, 2022
d739bf9
changed swap -> send
0xpApaSmURf Nov 17, 2022
554c240
removed DS_Store
0xpApaSmURf Nov 17, 2022
164ee34
removed typechain types from frontend
0xpApaSmURf Nov 17, 2022
12cd802
removed .yarn
0xpApaSmURf Nov 17, 2022
a89bc49
removed typechain types from hardhat folder
0xpApaSmURf Nov 17, 2022
7db8aef
added premint for smooth unwraps
0xpApaSmURf Nov 17, 2022
7fb1985
removed .yarnrc.yml
0xpApaSmURf Nov 17, 2022
4cc4a22
added comments to contract
0xpApaSmURf Nov 17, 2022
d63c0bb
simplfied hardhat config
0xpApaSmURf Nov 17, 2022
e64c3ee
changed typechain types folder due to copying issues
0xpApaSmURf Nov 17, 2022
0cb47d1
removed typechain artifacts again
0xpApaSmURf Nov 17, 2022
094759b
updated default hardhat node chainId
0xpApaSmURf Nov 17, 2022
97a74a1
updated default contract addresses
0xpApaSmURf Nov 17, 2022
6daccfa
fixed script that deploys and prewraps ERC20
0xpApaSmURf Nov 17, 2022
b087444
updated default cERC20 deployment address
0xpApaSmURf Nov 17, 2022
917b635
standardised localhost chainId to 1337
0xpApaSmURf Nov 17, 2022
43ea625
added toasts for error display
0xpApaSmURf Nov 17, 2022
4fca027
added error toast for failed wallet connection
0xpApaSmURf Nov 17, 2022
f86032b
placed full tx flow in try/catch
0xpApaSmURf Nov 17, 2022
74057a1
Fixed trade -> transfer on send page
0xpApaSmURf Nov 17, 2022
20d5720
updated and fixed tasks
0xpApaSmURf Nov 22, 2022
ec519a4
removed artifact of copied utils from the airdrop example
0xpApaSmURf Nov 22, 2022
40226fa
removed reference to claimingperiod
0xpApaSmURf Nov 22, 2022
bbe5b14
refactored getContract methods
0xpApaSmURf Nov 22, 2022
fec117b
fixed typo
0xpApaSmURf Nov 22, 2022
574f928
added clarity on where typchain artifacts end up
0xpApaSmURf Nov 22, 2022
a7639ce
updated package.json and added license and copyright files
0xpApaSmURf Nov 22, 2022
bf11d0b
migrated to rainbowkit and wagmi from web3context
0xpApaSmURf Nov 22, 2022
9bc5b1f
removed web3contextprovider, updated gitignore for typechain types
0xpApaSmURf Nov 22, 2022
1e28207
Removed Kovan from supported networks
0xpApaSmURf Nov 23, 2022
a0a086e
Updated contract addresses for supported networks
0xpApaSmURf Nov 23, 2022
31c8839
Fixed bug where view modifiers caused HBT to fail
0xpApaSmURf Nov 23, 2022
39a7be1
Changed to GPLv3 license header
0xpApaSmURf Nov 23, 2022
f4d39a0
Updated package.json, typescript version to 4.7.4
0xpApaSmURf Nov 23, 2022
fa11dfd
Added optional hardhat accounts
0xpApaSmURf Nov 23, 2022
314eafe
updated main build script to perform it non-concurrently
0xpApaSmURf Nov 23, 2022
32c415b
uses SPDX license identifier in package.json
0xpApaSmURf Nov 23, 2022
96bcfb4
fixed build script
0xpApaSmURf Nov 23, 2022
3ea1b7f
add next as dev dependency for vercel
0xpApaSmURf Nov 23, 2022
f502177
claim hbt button now redirects to sandbox for nonlocal
0xpApaSmURf Nov 23, 2022
60a8c2b
claim erc20 button now links to faucet when not on localhost
0xpApaSmURf Nov 25, 2022
88b8480
fixed balances to use correct 18 decimals for display and transactions
0xpApaSmURf Nov 25, 2022
60d5eae
fixed number overflow on send page
0xpApaSmURf Nov 28, 2022
a9ae2f5
added footer with disclaimer and contract address
0xpApaSmURf Nov 29, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions cToken/.gitignore
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
8 changes: 8 additions & 0 deletions cToken/COPYRIGHT
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/>.”
637 changes: 637 additions & 0 deletions cToken/LICENSE

Large diffs are not rendered by default.

149 changes: 149 additions & 0 deletions cToken/README.md
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:

```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)
3 changes: 3 additions & 0 deletions cToken/frontend/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": ["plugin:react/recommended", "next/core-web-vitals"]
}
46 changes: 46 additions & 0 deletions cToken/frontend/.gitignore
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 added cToken/frontend/README.md
Empty file.
5 changes: 5 additions & 0 deletions cToken/frontend/next-env.d.ts
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.
7 changes: 7 additions & 0 deletions cToken/frontend/next.config.js
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']
}
};
40 changes: 40 additions & 0 deletions cToken/frontend/package.json
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"
}
}
33 changes: 33 additions & 0 deletions cToken/frontend/pages/_app.tsx
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;
Loading