Feedback request: Extension: Collateral Swap

Hey Compound,

I am Roman from the Wido team. We are currently building an Extension for Compound that will enable collateral swaps. This project received a grant from Compound as part of CGP 2.0.

In this post, I am asking for feedback on the proposed architecture and User Interface. This will also mark successful delivery of Milestone 1 and we will proceed to Milestone 2: implementation & beta launch.

Extension summary

The proposed collateral swap extension for the Compound III protocol will enable users to exchange any deposited collateral, even if the collateral is locked due to an open borrowing position. To achieve this, Wido will utilize flash loans.

User Interface

A preliminary wireframe of the user interface for exchanging collateral is provided below. We aim to develop a UI based on this wireframe during Milestone 2: Beta Launch and integrate it as an extension in the web app. Please note that the numbers depicted in the figure are for illustrative purposes only and do not represent actual values.

The UI will allow users to choose the collateral and the desired amount to swap. Subsequently, they can select the collateral they wish to receive in exchange. To help users comprehend the implications of their decisions, metrics displaying the current (before the swap) and target (after the swap) position summary will be shown. We plan to present metrics similar to those currently available on

Once the user inputs the collateral to swap, the amount, and the collateral to obtain, Wido will determine an optimal swap route and present the user with a guaranteed minimum amount of collateral to be received after the swap. At this point, users can review the Guaranteed Amount value and decide if it aligns with their expectations.

Smart contract architecture

The diagram below illustrates our proposed architecture for smart contracts to facilitate the collateral swap for Compound users.

We propose creating a new contract called WidoFlashLoan, which will manage the process of taking a flash loan from IERC3156FlashLender (such as Aave), depositing and withdrawing collateral on the Compound Comet contract, and swapping the collateral using the WidoRouter contract.

The user will initiate the collateral swap process by directly interacting with the WidoFlashLoan contract in step 1. The user must grant permission to WidoFlashLoan to manage their positions. In step 2, the WidoFlashLoan contract will obtain a flash loan from an IERC3156FlashLender-compatible service using the flashLoan() method. Once the loan is received, the WidoFlashLoan contract will be called back through the onFlashLoan() method in step 3, as it implements IERC3156FlashBorrower.

The WidoFlashLoan contract will then execute a series of methods on the Comet contract, which include the following steps:

Step 4: supplyTo(): to deposit the collateral borrowed through the flash loan into the user’s position.

Step 5: withdrawFrom(): to withdraw the collateral the user wants to swap.

Finally, in steps 6 and 7, the WidoRouter will carry out the collateral swap and return it to the WidoFlashLoan to fulfill the flash loan obligation.


In conjunction with this grant, we propose developing a JavaScript SDK to enable other applications to integrate Compound collateral swaps directly into their user interfaces seamlessly. The SDK will offer the following methods:

  • getUserCollaterals(): returns a list of user collaterals and their balances for a specific Comet contract.
  • getSupportedCollaterals(): returns a list of collaterals supported by the Comet contract.
  • getUserCurrentPosition(): returns Collateral Value, Liquidation Point, Borrow Capacity, and Available to Borrow for the current user position.
  • getUserPredictedPosition(): returns Collateral Value, Liquidation Point, Borrow Capacity, and Available to Borrow for the user’s position after the swap is completed.
  • getCollateralSwapRoute(): returns the best swap route for the WidoRouter.
  • swapCollateral(): swaps collateral and returns the transaction hash.


There are various fees associated with the process explained above, mainly:

  • DEX fee, for performing the swap, i.e. on Uniswap
  • Flash loan fee

In addition to the existing fees, Wido plans to implement an extra service fee of 0.3% per collateral swap. We are happy to share the fee evenly (50:50) between Wido and the user interface responsible for initiating the collateral swap.

We believe this model will create healthy incentives for the UIs to drive usage for Compound.

Note: Adam B. from Compound expressed that Compound will pass on the fees part. So for transactions initiated from the web app, 100% of the fee will go to Wido. For other integrators, we propose to share the fee 50:50.

Conclusion and next steps

We are sharing this document with the Compound team for preliminary feedback, that will lead to the successful completion of Milestone 1. Next, Wido team will continue with Milestone 2 following the grant proposal specified on Questbook.


Hey, nice work :smile:

I created a cloneable redesign of your concept:

Looking forward to seeing this live!

Wish you the best,

1 Like