-
-
-
1) Deposit USDC
-
2) Earn passive lending yield from Aave
-
3) Use Chainlink Keepers to execute DCA at regular intervals
-
4) Retrieve deposit from Aave
-
5) Swap USDC for wBTC via Uniswap
-
6) Send DCA-swapped wBTC directly to user
-
Smart contract architecture
-
Initial Deposit into Aave lending pools
-
Dollar Cost Averaging investments via Chainlink Keepers and Uniswap
Inspiration
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.
However, DCA strategies are currently scarcely available, even amongst centralized exchanges. With the composability of DeFi protocols, there is a better way to conduct Dollar-Cost-Averaging strategies using smart contracts that is both permissionless and straightforward.
What it does
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.
Aave lending yields (in the form of aTokens) and Uniswap token conversions are all automatically accrued to users. They can also cancel their jobs any time to retrieve remaining funds.
Here is how it works:
Deposits
1) 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.
2) In the backend, this registers a DCA job internally that is configured to run during each time interval.
3) This initial balance is supplied to Aave lending pools, where it will earn passive lending yield.
Dollar-Cost-Averaging Investments
1) 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.
2) During each job, the investment amount, 100 USDC in our example, is withdrawn from the lending pool.
3) 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.
4) Swapped tokens can be directly transferred to user, minimizing custodial risk.
How we built it
Drip Investor is built utilizing Solidity for smart contract development, in a Hardhat environment, and tested using Waffle/Chai. Its functionality is via integrations with DeFi protocols Aave, Uniswap, and the decentralized oracle network of Chainlink Keepers to maintain time-triggered actions.
Challenges we ran into
Due to the different integrations, there were many interfaces and user flows to manage. Creating a composable, modular system was the goal so that future versions would have more optionality revolving around stablecoin deposit types and investment token types, and it proved difficult. Smart contract interactions and architecture, in separation of concerns, was also a challenge.
In order to deploy on Polygon Mumbai testnet, we also need the Uniswap swapRouter address, which has been difficult to locate.
Accomplishments that we're proud of
From a one-person team, we've architected and implemented the smart contract infrastructure that will underpin the Drip Investor dapp, while also allowing future extensibility of options - from which DEX is used, to the frequency of investment, to the tokens that are used for inputs and outputs.
What we learned
It was my first time integrating a smart contract with Aave and Uniswap protocols, as well as Chainlink Keepers. It was great to learn how to execute swaps via Uniswap, and make deposits and withdrawals into lending pools via Aave, and create a Keepers compatible interface to implement time-based triggers.
What's next for Drip Investor
There are many areas to develop.
- 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 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
Built With
- aave
- chainlink
- hardhat
- polygon
- solidity
- uniswap
- waffle
Log in or sign up for Devpost to join the conversation.