├── .github
└── workflows
│ └── ci.yml
├── .gitignore
├── .gitlab-ci.yml
├── .solcover.js
├── README.md
├── app
├── .gitignore
├── README.md
├── package-lock.json
├── package.json
├── public
│ ├── favicon.ico
│ ├── index.html
│ └── manifest.json
├── src
│ ├── App.css
│ ├── App.js
│ ├── App.test.js
│ ├── MyComponent.js
│ ├── MyContainer.js
│ ├── drizzleOptions.js
│ ├── index.css
│ ├── index.js
│ ├── logo.png
│ └── serviceWorker.js
└── yarn.lock
├── bitbucket-pipelines.yml
├── contracts
├── Migrations.sol
└── mocks
│ └── DaiMock.sol
├── migrations
├── 1_initial_migration.js
└── 2_deploy_contracts.js
├── package-lock.json
├── package.json
├── test
└── myTest.js
└── truffle-config.js
/.github/workflows/ci.yml:
--------------------------------------------------------------------------------
1 | name: ci
2 |
3 | on: [push]
4 |
5 | jobs:
6 | build:
7 |
8 | runs-on: ubuntu-latest
9 |
10 | strategy:
11 | matrix:
12 | node-version: [10.x]
13 |
14 | steps:
15 | - uses: actions/checkout@v1
16 |
17 | - name: Use Node.js ${{ matrix.node-version }}
18 | uses: actions/setup-node@v1
19 | with:
20 | node-version: ${{ matrix.node-version }}
21 |
22 | - name: test
23 | run: |
24 | npm install -g truffle
25 | npm install -g coveralls
26 | npm install
27 | npm run test
28 | npm run coverage
29 | env:
30 | CI: true
31 |
32 | - name: Coveralls
33 | uses: coverallsapp/github-action@master
34 | with:
35 | github-token: ${{ secrets.GITHUB_TOKEN }}
36 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | node_modules
2 | build
3 | app/src/contracts
4 | .DS_Store
5 | *.swp
6 | coverage
7 | coverage.json
8 | coverageEnv
9 |
--------------------------------------------------------------------------------
/.gitlab-ci.yml:
--------------------------------------------------------------------------------
1 | image: node:lts
2 |
3 | stages:
4 | - test
5 |
6 | test:
7 | stage: test
8 | script:
9 | - npm install -g truffle
10 | - npm install -g coveralls
11 | - npm install
12 | - npm run test
13 | - npm run coverage
14 |
--------------------------------------------------------------------------------
/.solcover.js:
--------------------------------------------------------------------------------
1 | module.exports = {
2 | mocha: { reporter: 'spec' }
3 | }
4 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # DeFi Dapp Start Kit
2 |
3 | 
4 | [](https://coveralls.io/github/jklepatch/defi-dapp-starter-kit?branch=master)
5 |
6 | A Starter kit for Ethereum DeFi Dapps
7 |
8 | (in-progress...)
9 |
10 | ## Frontend
11 |
12 | * React
13 | * React-router (TODO)
14 | * Drizzle
15 | * Rimble UI ? Material UI? (TODO)
16 |
17 | ## Smart contract
18 |
19 | * Solidity 0.5
20 | * Truffle 0.5
21 | * Integrate with Dai (Integration with token done. TODO: Integration with CDP)
22 | * Integrate with Compound (TODO)
23 | * Integrate with Gnosis (TODO)
24 |
25 | ## Contract Mocks
26 |
27 | To develop locally, we need to mock all the DeFi contracts we interface
28 | with. All the mocks are in `contract/mocks`.
29 |
30 | To add mocks, you need to:
31 |
32 | * Add mock in `contracts/mocks`
33 | * Add deployment instructions in `migrations/2_deploy_contracts.js`
34 | * Add contract to drizzle options in `app/src/drizzleOptions.js`
35 |
36 | Sometime, the original contract is not ideal for a mock:
37 |
38 | * Uncompatible Solidity versions
39 | * Complex deployments, involving other contracts
40 |
41 | In this case, you need to create a custom Mock. It will need to have
42 | at least all the functions that you will use in your frontend. No
43 | need to implement these functions.
44 |
45 | ## Dai
46 |
47 | There are 2 integrations:
48 |
49 | * with the Dai token
50 | * with the Dai CDP (TODO)
51 |
52 | The integration with the Dai token is straightforward. This is just a
53 | standard ERC20 token, with all the usual functions (`transfer()`, `transferFrom()`, etc...).
54 |
--------------------------------------------------------------------------------
/app/.gitignore:
--------------------------------------------------------------------------------
1 | # See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
2 |
3 | # dependencies
4 | /node_modules
5 | /.pnp
6 | .pnp.js
7 |
8 | # testing
9 | /coverage
10 |
11 | # production
12 | /build
13 |
14 | # misc
15 | .DS_Store
16 | .env.local
17 | .env.development.local
18 | .env.test.local
19 | .env.production.local
20 |
21 | npm-debug.log*
22 | yarn-debug.log*
23 | yarn-error.log*
24 |
--------------------------------------------------------------------------------
/app/README.md:
--------------------------------------------------------------------------------
1 | This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app).
2 |
3 | ## Available Scripts
4 |
5 | In the project directory, you can run:
6 |
7 | ### `npm start`
8 |
9 | Runs the app in the development mode.
10 | Open [http://localhost:3000](http://localhost:3000) to view it in the browser.
11 |
12 | The page will reload if you make edits.
13 | You will also see any lint errors in the console.
14 |
15 | ### `npm test`
16 |
17 | Launches the test runner in the interactive watch mode.
18 | See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information.
19 |
20 | ### `npm run build`
21 |
22 | Builds the app for production to the `build` folder.
23 | It correctly bundles React in production mode and optimizes the build for the best performance.
24 |
25 | The build is minified and the filenames include the hashes.
26 | Your app is ready to be deployed!
27 |
28 | See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information.
29 |
30 | ### `npm run eject`
31 |
32 | **Note: this is a one-way operation. Once you `eject`, you can’t go back!**
33 |
34 | If you aren’t satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project.
35 |
36 | Instead, it will copy all the configuration files and the transitive dependencies (Webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you’re on your own.
37 |
38 | You don’t have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn’t feel obligated to use this feature. However we understand that this tool wouldn’t be useful if you couldn’t customize it when you are ready for it.
39 |
40 | ## Learn More
41 |
42 | You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started).
43 |
44 | To learn React, check out the [React documentation](https://reactjs.org/).
45 |
46 | ### Code Splitting
47 |
48 | This section has moved here: https://facebook.github.io/create-react-app/docs/code-splitting
49 |
50 | ### Analyzing the Bundle Size
51 |
52 | This section has moved here: https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size
53 |
54 | ### Making a Progressive Web App
55 |
56 | This section has moved here: https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app
57 |
58 | ### Advanced Configuration
59 |
60 | This section has moved here: https://facebook.github.io/create-react-app/docs/advanced-configuration
61 |
62 | ### Deployment
63 |
64 | This section has moved here: https://facebook.github.io/create-react-app/docs/deployment
65 |
66 | ### `npm run build` fails to minify
67 |
68 | This section has moved here: https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify
69 |
--------------------------------------------------------------------------------
/app/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "app",
3 | "version": "0.1.0",
4 | "private": true,
5 | "dependencies": {
6 | "@drizzle/react-components": "^1.5.0",
7 | "@drizzle/react-plugin": "^1.5.0",
8 | "@drizzle/store": "^1.5.0",
9 | "react": "^16.11.0",
10 | "react-dom": "^16.11.0",
11 | "react-scripts": "^3.2.0"
12 | },
13 | "scripts": {
14 | "start": "react-scripts start",
15 | "build": "react-scripts build",
16 | "test": "react-scripts test",
17 | "eject": "react-scripts eject"
18 | },
19 | "eslintConfig": {
20 | "extends": "react-app"
21 | },
22 | "browserslist": [
23 | ">0.2%",
24 | "not dead",
25 | "not ie <= 11",
26 | "not op_mini all"
27 | ]
28 | }
29 |
--------------------------------------------------------------------------------
/app/public/favicon.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jklepatch/defi-dapp-starter-kit/65c282d22b403257dd0723977c1236be1ed3021a/app/public/favicon.ico
--------------------------------------------------------------------------------
/app/public/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
Examples of how to get started with Drizzle in various situations.
16 |
17 |
18 | {/*
19 |
20 |
21 |
Active Account
22 |
23 |
24 |
25 |
26 |
SimpleStorage
27 |
28 | This shows a simple ContractData component with no arguments, along with
29 | a form to set its value.
30 |
31 |
32 | Stored Value:
33 |
34 |
35 |
36 |
37 |
38 |
39 |
TutorialToken
40 |
41 | Here we have a form with custom, friendly labels. Also note the token
42 | symbol will not display a loading indicator. We've suppressed it with
43 | the hideIndicator prop because we know this variable is
44 | constant.
45 |
46 |
47 | Total Supply:
48 | {" "}
53 |
54 |
55 |
56 | My Balance:
57 |
62 |
63 |
Send Tokens
64 |
69 |
70 |
71 |
ComplexStorage
72 |
73 | Finally this contract shows data types with additional considerations.
74 | Note in the code the strings below are converted from bytes to UTF-8
75 | strings and the device data struct is iterated as a list.
76 |
77 |
78 | String 1:
79 |
80 |
81 |
82 | String 2:
83 |
84 |
85 | Single Device Data:
86 |
87 |
88 | */}
89 |
90 | );
91 |
--------------------------------------------------------------------------------
/app/src/MyContainer.js:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 | import MyComponent from "./MyComponent";
3 | import { DrizzleContext } from "@drizzle/react-plugin";
4 |
5 | function MyContainer() {
6 | return (
7 |
8 | {({accounts}) => (
9 |
10 | )}
11 |
12 | );
13 | }
14 |
15 | export default MyContainer;
16 |
--------------------------------------------------------------------------------
/app/src/drizzleOptions.js:
--------------------------------------------------------------------------------
1 | import DaiMock from "./contracts/DaiMock.json";
2 |
3 | const options = {
4 | web3: {
5 | block: false,
6 | fallback: {
7 | type: "ws",
8 | url: "ws://127.0.0.1:8545",
9 | },
10 | },
11 | contracts: [DaiMock],
12 | polls: {
13 | accounts: 1500,
14 | },
15 | };
16 |
17 | export default options;
18 |
--------------------------------------------------------------------------------
/app/src/index.css:
--------------------------------------------------------------------------------
1 | body {
2 | margin: 0;
3 | padding: 0;
4 | font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Roboto", "Oxygen",
5 | "Ubuntu", "Cantarell", "Fira Sans", "Droid Sans", "Helvetica Neue",
6 | sans-serif;
7 | -webkit-font-smoothing: antialiased;
8 | -moz-osx-font-smoothing: grayscale;
9 | }
10 |
11 | code {
12 | font-family: source-code-pro, Menlo, Monaco, Consolas, "Courier New",
13 | monospace;
14 | }
15 |
--------------------------------------------------------------------------------
/app/src/index.js:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 | import ReactDOM from 'react-dom';
3 | import './index.css';
4 | import App from './App';
5 | import * as serviceWorker from './serviceWorker';
6 |
7 | ReactDOM.render(, document.getElementById('root'));
8 |
9 | // If you want your app to work offline and load faster, you can change
10 | // unregister() to register() below. Note this comes with some pitfalls.
11 | // Learn more about service workers: http://bit.ly/CRA-PWA
12 | serviceWorker.unregister();
13 |
--------------------------------------------------------------------------------
/app/src/logo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jklepatch/defi-dapp-starter-kit/65c282d22b403257dd0723977c1236be1ed3021a/app/src/logo.png
--------------------------------------------------------------------------------
/app/src/serviceWorker.js:
--------------------------------------------------------------------------------
1 | // This optional code is used to register a service worker.
2 | // register() is not called by default.
3 |
4 | // This lets the app load faster on subsequent visits in production, and gives
5 | // it offline capabilities. However, it also means that developers (and users)
6 | // will only see deployed updates on subsequent visits to a page, after all the
7 | // existing tabs open on the page have been closed, since previously cached
8 | // resources are updated in the background.
9 |
10 | // To learn more about the benefits of this model and instructions on how to
11 | // opt-in, read http://bit.ly/CRA-PWA
12 |
13 | const isLocalhost = Boolean(
14 | window.location.hostname === 'localhost' ||
15 | // [::1] is the IPv6 localhost address.
16 | window.location.hostname === '[::1]' ||
17 | // 127.0.0.1/8 is considered localhost for IPv4.
18 | window.location.hostname.match(
19 | /^127(?:\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}$/
20 | )
21 | );
22 |
23 | export function register(config) {
24 | if (process.env.NODE_ENV === 'production' && 'serviceWorker' in navigator) {
25 | // The URL constructor is available in all browsers that support SW.
26 | const publicUrl = new URL(process.env.PUBLIC_URL, window.location.href);
27 | if (publicUrl.origin !== window.location.origin) {
28 | // Our service worker won't work if PUBLIC_URL is on a different origin
29 | // from what our page is served on. This might happen if a CDN is used to
30 | // serve assets; see https://github.com/facebook/create-react-app/issues/2374
31 | return;
32 | }
33 |
34 | window.addEventListener('load', () => {
35 | const swUrl = `${process.env.PUBLIC_URL}/service-worker.js`;
36 |
37 | if (isLocalhost) {
38 | // This is running on localhost. Let's check if a service worker still exists or not.
39 | checkValidServiceWorker(swUrl, config);
40 |
41 | // Add some additional logging to localhost, pointing developers to the
42 | // service worker/PWA documentation.
43 | navigator.serviceWorker.ready.then(() => {
44 | console.log(
45 | 'This web app is being served cache-first by a service ' +
46 | 'worker. To learn more, visit http://bit.ly/CRA-PWA'
47 | );
48 | });
49 | } else {
50 | // Is not localhost. Just register service worker
51 | registerValidSW(swUrl, config);
52 | }
53 | });
54 | }
55 | }
56 |
57 | function registerValidSW(swUrl, config) {
58 | navigator.serviceWorker
59 | .register(swUrl)
60 | .then(registration => {
61 | registration.onupdatefound = () => {
62 | const installingWorker = registration.installing;
63 | if (installingWorker == null) {
64 | return;
65 | }
66 | installingWorker.onstatechange = () => {
67 | if (installingWorker.state === 'installed') {
68 | if (navigator.serviceWorker.controller) {
69 | // At this point, the updated precached content has been fetched,
70 | // but the previous service worker will still serve the older
71 | // content until all client tabs are closed.
72 | console.log(
73 | 'New content is available and will be used when all ' +
74 | 'tabs for this page are closed. See http://bit.ly/CRA-PWA.'
75 | );
76 |
77 | // Execute callback
78 | if (config && config.onUpdate) {
79 | config.onUpdate(registration);
80 | }
81 | } else {
82 | // At this point, everything has been precached.
83 | // It's the perfect time to display a
84 | // "Content is cached for offline use." message.
85 | console.log('Content is cached for offline use.');
86 |
87 | // Execute callback
88 | if (config && config.onSuccess) {
89 | config.onSuccess(registration);
90 | }
91 | }
92 | }
93 | };
94 | };
95 | })
96 | .catch(error => {
97 | console.error('Error during service worker registration:', error);
98 | });
99 | }
100 |
101 | function checkValidServiceWorker(swUrl, config) {
102 | // Check if the service worker can be found. If it can't reload the page.
103 | fetch(swUrl)
104 | .then(response => {
105 | // Ensure service worker exists, and that we really are getting a JS file.
106 | const contentType = response.headers.get('content-type');
107 | if (
108 | response.status === 404 ||
109 | (contentType != null && contentType.indexOf('javascript') === -1)
110 | ) {
111 | // No service worker found. Probably a different app. Reload the page.
112 | navigator.serviceWorker.ready.then(registration => {
113 | registration.unregister().then(() => {
114 | window.location.reload();
115 | });
116 | });
117 | } else {
118 | // Service worker found. Proceed as normal.
119 | registerValidSW(swUrl, config);
120 | }
121 | })
122 | .catch(() => {
123 | console.log(
124 | 'No internet connection found. App is running in offline mode.'
125 | );
126 | });
127 | }
128 |
129 | export function unregister() {
130 | if ('serviceWorker' in navigator) {
131 | navigator.serviceWorker.ready.then(registration => {
132 | registration.unregister();
133 | });
134 | }
135 | }
136 |
--------------------------------------------------------------------------------
/bitbucket-pipelines.yml:
--------------------------------------------------------------------------------
1 | pipelines:
2 | default:
3 | - step:
4 | image: node/lts
5 | name: test
6 | script:
7 | - npm install -g truffle
8 | - npm install -g coveralls
9 | - npm install
10 | - npm run test
11 | - npm run coverage
12 |
--------------------------------------------------------------------------------
/contracts/Migrations.sol:
--------------------------------------------------------------------------------
1 | pragma solidity >=0.4.21 <0.6.0;
2 |
3 | contract Migrations {
4 | address public owner;
5 | uint public last_completed_migration;
6 |
7 | constructor() public {
8 | owner = msg.sender;
9 | }
10 |
11 | modifier restricted() {
12 | if (msg.sender == owner) _;
13 | }
14 |
15 | function setCompleted(uint completed) public restricted {
16 | last_completed_migration = completed;
17 | }
18 |
19 | function upgrade(address new_address) public restricted {
20 | Migrations upgraded = Migrations(new_address);
21 | upgraded.setCompleted(last_completed_migration);
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/contracts/mocks/DaiMock.sol:
--------------------------------------------------------------------------------
1 | pragma solidity ^0.5.12;
2 |
3 | import 'openzeppelin-solidity/contracts/token/ERC20/ERC20.sol';
4 | import 'openzeppelin-solidity/contracts/token/ERC20/ERC20Detailed.sol';
5 |
6 | contract DaiMock is ERC20, ERC20Detailed {
7 | constructor()
8 | public
9 | ERC20Detailed('Dai Stablecoin v1', 'DAI', 18) {}
10 |
11 | function faucet(uint amount) external {
12 | _mint(msg.sender, amount);
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/migrations/1_initial_migration.js:
--------------------------------------------------------------------------------
1 | var Migrations = artifacts.require("Migrations");
2 |
3 | module.exports = function(deployer) {
4 | deployer.deploy(Migrations);
5 | };
6 |
--------------------------------------------------------------------------------
/migrations/2_deploy_contracts.js:
--------------------------------------------------------------------------------
1 | const DaiMock = artifacts.require("mocks/DaiMock.sol");
2 |
3 | module.exports = function(deployer) {
4 | deployer.deploy(DaiMock);
5 | };
6 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "drizzle-box",
3 | "version": "1.0.0",
4 | "description": "",
5 | "main": "truffle-config.js",
6 | "directories": {
7 | "test": "test"
8 | },
9 | "scripts": {
10 | "test": "truffle test",
11 | "coverage": "truffle run coverage"
12 | },
13 | "repository": {
14 | "type": "git",
15 | "url": "git+https://github.com/truffle-box/drizzle-box.git"
16 | },
17 | "keywords": [],
18 | "author": "",
19 | "license": "ISC",
20 | "bugs": {
21 | "url": "https://github.com/truffle-box/drizzle-box/issues"
22 | },
23 | "homepage": "https://github.com/truffle-box/drizzle-box#readme",
24 | "dependencies": {
25 | "openzeppelin-solidity": "^2.4.0"
26 | },
27 | "devDependencies": {
28 | "eth-gas-reporter": "^0.2.12",
29 | "solidity-coverage": "^0.7.0-beta.2"
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/test/myTest.js:
--------------------------------------------------------------------------------
1 | contract('MyTest', () => {
2 | it('My first test', async () => {
3 | //your test here...
4 | });
5 | });
6 |
--------------------------------------------------------------------------------
/truffle-config.js:
--------------------------------------------------------------------------------
1 | const path = require("path");
2 |
3 | module.exports = {
4 | // See
5 | // to customize your Truffle configuration!
6 | contracts_build_directory: path.join(__dirname, "app/src/contracts"),
7 | compilers: {
8 | solc: {
9 | version: '0.5.12'
10 | }
11 | },
12 | mocha: {
13 | reporter: 'eth-gas-reporter',
14 | reporterOptions : { showTimeSpent:true }
15 | },
16 | plugins: ["solidity-coverage"]
17 | };
18 |
--------------------------------------------------------------------------------