For the majority of crypto investors, it isn’t about degenerate day trading with 5x leverage. Or about flipping NFT poop emojis for profit. Instead, the commonly preferred method is the tried and true Dollar-Cost-Averaging - a simple, unemotional albeit boring approach.
Dollar-Cost-Averaging is the practice of purchasing the same amount of an underlying asset at regular intervals, regardless of its price. It is designed to lower the average cost per share and reduce volatility, which is especially important to onboarding the non-degenerates amongst us into crypto.
Drip Investor is a dapp that allows permissionless Dollar-Cost-Averaging of tokenized assets. Users can deposit stablecoins, which earn passive lending yield. During regular intervals, stablecoin tokens are withdrawn and swapped using decentralized exchanges to convert into investment tokens of choice.
Drip Investor is built via integrations with Aave, Uniswap, and Chainlink Keepers.
- System Requirements
- Quick Start
- User Guide
- Smart Contract & Mechanics
- Testing
- Design Patterns
- Further/Next Steps
- Node v16.14.0
- Hardhat v2.10.1
- Hardhat-Waffle v2.0.3
On Terminal 1 clone this repository and install its dependencies:
$ git clone https://github.com/yan-man/Drip-Investor.git
$ cd Drip-Investor
$ npm install
See Hardhat for more details.
Navigate to root directory, then start tests.
$ npx hardhat test
For test coverage:
$ npx hardhat coverage
On a new terminal (Terminal 3), go to the repository's root folder and run the script to deploy the collection of smart contracts and configure initial settings.
$ npx hardhat run scripts/deploy.js --network localhost
-
The user first deposits some amount of stablecoin into the dapp, specifying how much they would like to invest, what to invest in, and at what frequency of investment. For example, 1000 total USDC, investing 100 USDC per week on wrapped bitcoin.
*For this initial version, only weekly investments are allowed. Input stablecoins are configured to USDC and output tokens to WETH.
-
In the backend, this registers a DCA job internally that is configured to run during each time interval.
-
This initial balance is supplied to Aave lending pools, where it will earn passive lending yield.
-
At regular intervals (ie weekly), Chainlink Keepers are employed to help to execute the Dollar-Cost-Averaging investments by performing upkeep on our smart contract. It is essentially on-chain CRON jobs.
-
During each job, the investment amount, 100 USDC in our example, is withdrawn from the lending pool.
-
Then it is swapped for the desired investment token (ie wBTC) via Uniswap DEX. These investments occur periodically until either funds run out or users cancel their jobs.
-
Swapped tokens can be directly transferred to user, minimizing custodial risk.
The core contract interface for users to interact with. It manages the other helper contracts and has overall admin power. When creating or cancelling jobs, users should invoke functions from DCAManager
.
Manages user-created DCA job, which are represented by an investment amount, frequency, start date, and job owner. Also retrieves Job info as needed by other contracts.
Manages deposits and withdrawals from the initial supply deposit into the Lending protocol. This is the contract that will be registered with Chainlink Keepers.
Manages interactions with the external API for the lending protocol of choice; in this initial version, it is only via Aave.
Manages interactions with the external API for the DEX of choice; in this initial version, it is only via Uniswap.
Library that manages the different DCA options which will be available - token type, DCA frequency, etc.
Library that manages Job struct.
- separation of concerns
- libraries
- Front end: create a React based app that can integrate with the smart contracts via ethers.js, allowing users to save and cancel DCA jobs. Also show users their transaction history and net profits, using TheGraph to retrieve event data, etc.
- Access Control: Currently smart contract functions are not restricted, as they should be in production. There are complicated interactions between contracts that need to be resolved.
Expand functionality:
-
cancel jobs: further develop UX and functionality for cancelled jobs.
-
optionality: Currently the deposit token (USDC) and the investment token (wETH) are not flexible options, as well as the choice of DEX (Uniswap) or lending pool (Aave). We still need to resolve, from a UX perspective, how much optionality we want to give end users in these choices.
-
Expand code coverage
- Hardhat: An Ethereum development task runner and testing network.
- Mocha: A JavaScript test runner.
- Chai: A JavaScript assertion library.
- Waffle: To have Ethereum-specific Chai assertions/matchers.
All non-boilerplate code is unlicensed. Yan Man 2022.