What do on-chain solvers even solve?

Protocol integration with The Commercium

FreshPizza
4 min readJul 16, 2022

In my previous adventure as a solidity developer I was working on a protocol that created tokenized indices with the goal of making that process permissionless. Meaning users could build and mange their own indices/vaults/funds/treasuries.

It was at a time where Ethereum gas prices where skyrocketing so we decided to build on Polygon where you couldn’t spend more then $5 for a transaction even if you wanted to. The first indices mainly contained blue chip DEFI tokens and stable coins. So nothing too niche.

When a user wanted to generate an index tokens they would execute a smart contract function that would then automatically buy all the assets that where part of said index.

Compared to other chains Polygon had pretty good liquidity for a variety of assets but it was scattered among many Dexes.

In fact, currently liquidity on Polygon is spread pretty broadly among no less then 11 Dexes:

Top 18 highest TVL protocols on Polygon

This of course meant that our contract would not be able to buy all required assets from just one DEX.

One of the Indices we build held the stable coin RAI. Do you want to know which DEX had the most liquidity for RAI….KyberSwap. Never heard of it? Exactly!

We effectively had two different options that would enable our contract to buy from multiple Dexes.

1 Use the API provided by DEX Aggregators such as 1Inch and Paraswap to receive ordering information that we could then feed to the smart contract via our front-end when a user purchased an index. We rejected that option as we did not want to tie the usage of the protocol to our front-end. In addition we as a decentralized organization didn’t want to make ourselves dependent on a private companies API that they could deny us at any time or start charging fees for. Naturally we would also be breaking their ToS by allowing users from the US to use our services.

2 Build our own on-chain aggregator.

Computing the best trading route off-chain was not an options as we would once again tie the usage of the protocol to our front-end. In addition we also wanted to enable users to eventually re-balance their indices using keepers which wouldn’t have access to our off-chain solution.

Although we where successful in creating an on-chain aggregator that could service our current indices it came with a large amount of maintenance. The gas-limit on Polygon prevented us from including all Dexes so we had to limit our selection to the ones which had the highest liquidity for the assets that we needed. Liquidity would travel from DEX to DEX as they each enabled/disabled incentives and as new Dexes entered the ecosystem. So we had to adjust or replace the aggregator on a regular basis. Additional work load came from Dexes like UniswapV3 where you have to specify the fee of the pool you want to trade in. If liquidity for a pair went from the 1% fee pool to the 0.3% pool then that required a manual adjustment on our end.

Some token liquidity was so spread out that our index ended up being the single largest holder of some tokens on Polygon. That circumstance forced us to bridge more assets from Ethereum in order to re-balance the index without users incurring huge losses.

Not all chains have liquidity that is as dispersed as on Polygon but no chain has a single DEX where all liquidity has accrued. Furthermore, we can be pretty sure that StarkNet will have similar issues to Polygon with over 6 Dexes being announced before there are even any tokens to be traded. And naturally they will be throwing all the incentives they can at LPs and other protocols in order to accumulate liquidity.

Any on-chain protocol that regularly and permissionlessly allows the selling/buying of tokens will have to maintain multiple DEX interfaces and keep track of liquidation accrual. That is unless there happens to be a single protocol/interface that provides an aggregation of all available Dexes…

Enter The Commercium!

The Commercium is a platform where anyone can add their own DEX aggregation algorithms (written in Cairo) that can then be used permissionlessly by any individual or protocol.

In order to fulfill the varying security and decentralization requirements there will be a wide selection of official solvers that vary in complexity and that are audited. These will also include immutable and up-gradable variants. Protocols can choose whether to utilize a solver that is immutable and therefore provides high security but might degrade in performance over time. Or a solver that is up-gradable and will be maintained by Adeptus Digitales. This will require protocols to trust in the work performed by AD but it also means that protocols will not have to switch to a new solver on a regular basis.

A prime principle of AD is that users of the protocol should not incur any additional fees on top of the fee charged by the Dexes. Although any individual could add a solver to the platform that charges a fee, all official solvers deployed by AD will not do so.

In one of my next post I will dive into how AD as well as independent developers can still be incentivized to continuously create and maintain solvers without having to charge the users a fee.

Have a lovely day. And as always praise be to our future AI overlords.

--

--