Automated DeFi Limit Orders on top of lending protocols

There are vast amount of untapped and under-utilised stablecoin liquidity is sitting idle in protocols. This is partly due to liquidity mining events generated by some of the largest protocols like COMP and AAVE.

Instadapp has become one of the most significant and fertile lands for farming AAVE and COMP. In particular, many users with large balances are looping their positions to maximise their returns by 4 to 10x, usually accomplished with stable coin pairs like DAI to DAI or USDC to USDC.

Let’s take an example of a COMP farmer who has a starting capital of 10M USDC. This farmer can maximize the exposure by up to 40M USDC collateral & 30M USDC debt. This position mines COMP with an exposure equivalent to 70M.

However, while the assets are provided, they gain interest, but they essentially sit idle. What if the assets in this position could be used as a liquidity source for stablecoin swaps while earning COMP & AAVE, thus increasing their utility and capital efficiency.

On Compound, users can make a limit order up to 7x their net value, while on Aave, they can go up to 9x. At the time of writing this post, Instadapp has 28 users with a total of 35 positions with more than 10M DAI/USDC in collateral/debt in Aave/Compound - which adds up to ~$2.31B collateral & ~$1.83B debt and potentially ~$4.14B available capital for automated stablecoin swaps.

For example, the user described above can provide liquidity for stablecoin to farm COMP/AAVE and earn market-making fees by creating stablecoin swap orders on top of that lending position, making an entirely new source of cashflow.

Also, when the user sets a collateral & debt swap limit order. Their collateral & debt is in USDC. The user can sell at a slight premium, increasing their collateral & minimising their debt over time.

(see the example below).

The Instadapp Protocol enables users to create stablecoin orders for and within their DeFi deposits & borrowings on Aave and Compound.

Users can set a limit to buy & sell. For example, a 10M USDC debt user can create a limit order of a range to sell 1 USDC at 1.0005 DAI and buy 1 USDC at 0.9995 DAI. That means the user’s position will sell DAI & USDC at a premium. The user’s position will only revolve under that defined range limits.

  • When all debt is in USDC: The user’s position will swap from DAI to USDC at premium and trade vice-versa. Receive USDC → Payback USDC → Borrow DAI → Return DAI.
  • When all debt is in DAI: The user’s position will swap from USDC to DAI at premium and trade vice-versa. Receive DAI → Payback DAI → Borrow USDC → Return USDC.
  • When some debt is in DAI & some in USDC: The user’s position will swap from USDC to DAI or DAI to USDC at a premium.
    • USDC debt will provide USDC to DAI swap for traders: Receive USDC → Payback USDC → Borrow DAI → Return DAI.
    • DAI debt will provide DAI to USDC swap for traders: Receive DAI → Payback DAI → Borrow USDC → Return USDC.

The above example is of debt swap, understand similarly for collateral swap.

Extra Thoughts:

Currently, ~$1.3B DAI is being held up in Compound & Aave, and DAI is unstable for a while. The range orders like this will mobilize the idle DAI sitting on lending protocols like Compound & Aave as market makers increase the DAI supply in the market, meaning less DAI being generated using USDC.

  • Increases peg stability with the minimal market intrusion.
  • Generates a passive payback for debts over time. Increased stablecoin instability decreases the holder’s overall liabilities, winning in uncertain times!

Instadapp Protocol is in the best position to build this system, creating market efficiency and adding a new stream of income for Instadapp users by utilizing idle assets. I look forward to hearing your thoughts.

15 Likes

Sounds interesting, but how do you make the taker (who is swapping USDC for DAI) to wait for you to return the DAIs? You need to operate with a dex that allows you to take the taker’s money (USDC) in a kind of flash loan and only later in the transaction (after the payback-followed-by-borrow) to return the promised amount of DAI.

3 Likes

It’s simple. It’ll be one atomic transaction for a trader there will be a function swap in that function payback & borrow (or deposit and withdraw) will happen. For traders, they don’t need to know how it happened. There is no flashloan needed to do any swap.

2 Likes

It’s an interesting proposal. I was also thinking of certain Maker vaults especially stablecoin collaterized (such as USDC) that have a large debt that is sitting idle. And as there’s no mechanism to liquidate Maker vaults with stablecoin collateral, maybe it’s safer using this idle capital. What do you think?

3 Likes

Exactly! I had that in mind. I think that was the triggering point for my thoughts around this. I personally have a position blocked with the USDC-A vault and was thinking of a solution to put my vault on sale at 1:1 DAI to USDC as a market maker. I also have the whole concept of USDC-A vault in my head have to write down the contract structure but could be something INST governance should be fine to incentivize for developers to build.

5 Likes

Agreed. In fact, although PSM has solved Dai’s peg quite well, there are also certain spikes or crash in peg once in a while. For example, last month, some could even buy 1 Dai at 0.97 USDC.
https://dai.stablecoin.science/

What are some next steps?

1 Like

The major thing is currently almost all the USDC to DAI swaps are going through the PSM and the difference between buying and selling is around 0.4 - 0.6% depends on the swap size.

With DeFi Limit Order, users can set a limit even at 1 USDC = 0.9991 DAI and capture all the PSM trades while pushing the DAI from Compound & Aave out in the market hence decreasing the DAI via USDC.

Next steps. We’ll be starting the development this week. The development should be done by this or next week. Then the contracts will go through proper testing, verification & audits before making it publicly live for all the Instadapp users. Hopefully Automated DeFi Limit Orders should get live before July ends.

Any suggestions?

3 Likes

Interesting feature request here. Making sure I am wrapping my head around this process - there is no risk of liquidation with these swaps because of the incoming supply to the user, who then swaps the asset and returns it? Is this all being done while assets remain in the protocol (Compound, AAVE, Maker, etc.) and no need to withdraw the assets?

1 Like

Yeah! There is no risk. As the deposit happens first after that tokens get withdrawn same goes for payback and then borrow.

3 Likes

That’s an interesting feature. The market maker would have to be comfortable with his interest rate varying as his debt or collateral gets swapped.

2 Likes