project screenshot 1
project screenshot 2
project screenshot 3
project screenshot 4

DeCA

A dynamic protocol enabling gas-less, periodical automated token swaps. Users deposit funds into a periodic swap amount, and decentralized keepers trigger swaps on beat. Potential features include double-side staking, governance voting, asset-bundling, and adaptive fees.

DeCA

Created At

ETHOnline 2023

Project Description

DeCA is a simple but powerful defi primitive based on the classic investment concept of cost averaging. The name is a play on words of the most commonly discussed variant of this concept, the Daily Cost Average, and Decentralization, which our project very much stands for. We offer gasless, hands-off transactions that let even the smallest investors purchase the asset of their choice at the rate that makes sense to them.

Right now, if you want to continually invest into an crypto asset you have a few choices. You could go through centralized exchanges, where you'll pay hefty fees (upwards of 1% on Coinbase) and not hold your own keys. You could manually swap, but your emotions might change how much or how often you buy, and sometimes you'll just be busy. Or you could write or purchase a trading bot, something that simply is never going to be right for everyone, whether that's due to difficulty or cost.

With DeCA, you pick two assets, one to pay with, and one to buy. You choose the rate you want this trade to be made, whether that be every minute or once a month. Then you pick how many times you'd like to repeat this purchase. After that, you just deposit into the smart contract, and collect the purchased asset whenever you wish. You can also exit the protocol at any time.

How do we accomplish this on the backend? We use the keeper system, where anyone can trigger a valid buy and receive a small fee in exchange for paying the gas. As we're able to group many users' buys into one transaction, this keeper fee can be spread very thin across DeCA users. At scale this number could be less than a tenth of coinbase's fee. How does the contract determine if a buy is valid? Simply if the correct number of blocks has elapsed since the last purchase. On polygon there are two second blocks, so a one minute DeCA contract is every 30 blocks.

By cost averaging, investors get to make long term plans rather than acting rashly. They set their strategy, and let it ride, adjusting the buy amount here and there as needed. DeCA aims to make that process as easy, as safe, as decentralized, and most important, as SIMPLE as possible.

How it's Made

Our tech stack was founded on the wagmi + next.js + foundry boilerplate. We find this enjoyable to use as most of the rough edges of connecting are taken care of. We kept our styling simple and clean, so we didn't end up using any UI packages. Sometimes good ol' HTML (inside of tsx) is enough.

The main partner technology that we used was Polygon's excellent ethereum L2. We want to help usher more users into near gasless solutions.

We also have a naive shell script to trigger the keeper buys. In a production environment we would prefer to use an event based system, but a simple loop was good enough for demo purposes.

One thing that I really liked was the epoch system we built into the contract to rollup purchases into a flatter structures. Rather than storing each purchase individually, we're able to group them into larger time periods. This was inspired by the Solana staking system. In the same vein, you can only enter the protocol on epochs beginnings. We didn't get enough time to implement this concept in the UI, so we stuck with epochs with a length of 1. But the composability exists within the contracts.

On that note, the entire composability of the system is something we're proud of. Strategies can be with any swappable asset. The buy period can be as short as one block. Future extensions would be: more options for swap protocols, including multi-hop, governance voted on strategies, slippage controls, and multi-protocol spreading.

background image mobile

Join the mailing list

Get the latest news and updates