Inspiration

The core concept of blockchains and cryptocurrencies is decentralization but centralized crypto exchanges (CEX) appeal to more users due to their ease of use and the variety of services they provide. This irony has always been at the back of my head. Decentralized finance (DeFi) ecosystem lacking a variety of useful services is one of the main drawbacks of crypto and I wanted to take a step towards this problem in this hackathon.

Dollar-cost-averaging (DCA) is one of the most simple and popular investing strategies offered by centralized exchanges which is buying X amounts of something over a period of time, for example buying $100 worth of Ethereum every week. With the goal of bringing more utility to the DeFi ecosystem, I wanted to make a DCA protocol that is as easy to use as a centralized exchange but fully decentralized and automated.

What it does

EasyDCA is a protocol that allows users to create their own dollar-cost-averaging strategies. They choose the coin they want to accumulate, which stablecoin they want to use, and the buying period. They first approve the spending of the stablecoin they have chosen, for the automation to be able to work on its own. No user coin is locked during this process and the strategies which don't have enough allowance or balance automatically get stopped. Then they record the strategy to the smart contract by making a transaction. For example, they can create an order to buy $5 worth of Ethereum every week with USDC. Image illustrating how to create a DCA order

All strategies of all users are held in a heap structure ordered by their next purchase date. The registered Chainlink Upkeep has a custom trigger, it checks if the nearest purchase date has come. When the time comes Chainlink Automation automatically makes the purchase on a decentralized exchange (SpookySwap in the current demo) and sends the target coin to the user. Then the heap is reordered and it waits for the next closest purchase time. According to the example mentioned above, their purchases will get executed every week and $5 worth of Ethereum will be deposited into their wallet until they manually cancel the DCA or their balance/allowance runs out. Image illustrating Chainlink Automation

Users can see the historical data about the automated purchases made directly on the website. Useful statistics like the average price of purchase and total accumulated coins are also shown to the user in addition to single purchase statistics. Image illustrating past purchases

The Demo currently runs on Fantom Network as it is a cheap and fast layer 1 blockchain and uses SpookySwap as its DEX.

How I built it

Firstly, I started by working out the overview of the project on paper, including what to store in the smart contract and how to hold strategies efficiently. Later, I developed a simplified smart contract as if everything will run manually. After ensuring everything works as intended, I explored Chainlink's Automation service and made the smart contract work accordingly.

At that point, the smart contract was working automatically as intended so I started building the frontend with Next.js. Lastly, I spent my final time on gas optimization on the smart contract and UI/UX improvements on the website.

Challenges I ran into

The main challenge was gas. Smart contract development is unique in the sense that you need to be really efficient, thanks to the developments in technology websites or mobile applications can run practically flawlessly without many optimizations. However, smart contracts must be designed properly for them to scale without problems. And in the case of EasyDCA, I wanted to make it as scalable as it can get as a result during the hackathon most of my time has been spent on the design of storing and executing the DCA strategies.

Accomplishments that I'm proud of

I am really content with how EasyDCA turned out in this limited time. The smart contract works efficiently and it is scalable. The heap structure allows the Chainlink Automation to run in log(Number of DCAs Created) time which means the whole protocol can run cheaply and without facing any gas problems as it acquires more users. In addition, the overall design of the website is clean and easy to use which was one of my main goals. I am proud that it became a near-market-ready product.

What I learned

I have worked with Chainlink products before, but I haven't dived this deep into automation before and I am happy to have added that to my skill set. In addition, the whole design of the project taught me a lot about gas optimization and overall smart contract design.

Lastly, one of my main goals was to make EasyDCA easy to use and this made me think more like a UX designer rather than a coder. This was a little out of my comfort zone but I enjoyed the process.

What's next for EasyDCA

The first step will be to release it in beta to get user feedback and improve the product (mostly the UI/UX) accordingly as I am a firm believer in community-driven development.

Currently, the demo runs with a limited number of available coins and uses a single DEX. So an immediate next step would be to expand the number of available coins and the number of DEXs it is integrated with, the smart contract is written in a flexible way to allow this without much additional effort. In addition, it will be deployed to other EVM-based popular chains to serve more users.

A major upgrade to EasyDCA would be to develop a custom on-chain liquidity aggregation oracle and use it during automated purchases to let people get the most out of their tokens. There are some liquidity aggregators currently in the market but all of them rely on data computed outside of the chain which makes them impossible to use for automated purchases. So probably for an EasyDCA v2, developing an on-chain aggregation system that can use multiple decentralized exchanges will add substantial value.

Dollar-cost-averaging is only one of the popular strategies used by investors. With the mission of making DeFi more accessible and usable for the masses in mind, the next step for EasyDCA will be to implement more popular automatic strategies into the application. Hopefully one day, it can be a protocol for people to run their own custom investing strategies decentrally without the need for centralized exchanges.

Built With

Share this project:

Updates