Gelato-DCA: Automated Dollar Cost Averaging Dapp

Hello, Gelato community! :wave:

I’m currently working on a project that aims to make DCA’ing simple and easy, using Gelato network. Users can make their own DCA plan by selecting how often and how much money to spend for each DCA. After depositing the fund, Gelato will regularly swap them on DEXes according to the plan until the account runs out of fund (you can add more fund anytime!). It will initially be deployed on Polygon so that the fees are affordable. You can see the current working draft of the dapp here.

It’s still in a very early phase, so feel free to DM me if you are interested to contribute :grinning_face_with_smiling_eyes:

Also feel free to drop any feedback or feature wishes!

9 Likes

That’s awesome Willy, will definitely support you here!

Quick questions:

  1. What Oracle will you be using to execute market orders on e.g. quickswap when individual orders are executable? You should understand that DCA means that you will execute market orders at certain future times on behalf of your users, that’s why you need some sort of slippage protection to ensure that orders are not frontran. @brandon.cs might have some ideas around this.

  2. On which venue will you be executing the orders, quickswap?

Actually @brandon.cs worked on a DCA implementation at some point, he might be able to share some insights as well.

What might be an “easy way” of going about the implementation is the following:

  1. Create a contract where users can submit orders by storing how much they want to sell and how often they want to sell. This data you just store onchain. If they use MATIC, you just need one tx. If they use ERC20 tokens, they require 2 txs (1 approval).

  2. Create a resolver which returns the minimum out amount rate of the token pair from quickswap and encodes an exec function on an action contract (the one we created in step 1). Using this minimum out amount ensures that transactions dont get frontrun because Gelato bots will call the resolver off-chain and then use that payload to call the execution function on-chain.

  3. Now you just deposit some MATIC on app.gelato.network and then executions will happen every so often. I will sponsor the first 1000 transactions myself by depositing some MATIC on your behalf. If this works, then you can start thinking about implementing a biz model into this in which transactions actually pay for itself, but I would not worry about this for starters.

3 Likes

Thanks hilmar!

This is actually how I did it before for the Opyn automator! One question though, how secure is this? Is it possible for Gelato bots to tamper with the payload?

As for the second question, I’m thinking of allowing ETH/USDC pair first–a quick search shows Sushiswap has the most liquidity (3x of Quickswap) so I will probably use them.

yay, affirmative :grinning:

2 Likes

it is not enforced on chain on the gelato smart contracts, but you could also have some sort of cross check on the actual action contract which checks the slippage is in line with the pairs TWAP, but in general I would not worry about this for starters, especially as we will have staking pretty soon so bots can be taken accountable if they mess with the payload.

1 Like

Love this idea! A lot of DEXes have asked for this feature. I could see this getting adapted widely.

1 Like

Awesome initiative @willy !

@hilmarx @kassandra.eth - we should share some of our previous DCA code and tests with @willy , maybe invite him to our old repo there.

1 Like

You da man @willy !! Love your initiative here.
I’ve been following another dapp that achieves the same goal - Mean Finance.
Not sure if you are also familiar with them. Just thought of throwing it out there so that you may get some idea or inspiration out of it!

1 Like

Hey, first time I’ve heard of Mean Finance. Will check them out, thanks!

1 Like

@willy for inspiration you can check out:

We also built a small dummy UI for our DCA smart contracts which you could use. Also check out the open PR that @brandon.cs did where he tried to port it to polygon!

1 Like

Thanks @hilmarx, very helpful reference!

A little update: first version of contract is live on Ropsten.

Working on UI now.