Disclaimer: This post is written for educational purposes and does not constitute investment or financial advice.
In this post, we will explore the mechanics of the matching engine built into the architecture of PhutureDAO protocol. This post is the first of a three-part series showcasing how the Phuture system functions.
First, let’s answer the question ‘Why do we need a matching engine?’
The matching engine marries base and quote assets together in equal value to facilitate their deposit into their respective liquidity pool. In addition, the matching engine enables unbalanced liquidity provision.
The theory of the matching engine.
When a user invests USDC into the system it is swapped proportionally for each constituent asset in the index, and those index assets move into the matching pool. These index assets are part of the quote side of the pool in the PhutureDAO protocol, and each one must be matched with an equal value of base asset before they can be deposited into their respective liquidity pool. USDC is the only eligible base asset in the system.
At this point, you might be wondering why the quote assets need to be deposited into liquidity pools. The PhutureDAO protocol leverages liquidity pools to provide rebalancing pressure for index assets, ensuring that they are constantly moving towards their target weights. This allows for rebalancing at zero cost to the index holder. There is a lot more to discuss about the rebalancing system, but this provides enough context for the scope of this post. We shall revisit the rebalancing system in more depth in another blog post.
Continuing on. Since we already have the quote assets waiting, we require USDC from liquidity providers depositing tokens in an unbalanced ratio. An unbalanced ratio can be anything that differs from 50:50 but for the purpose of this walkthrough, let’s assume that the LPs deposit 100% USDC. In this instance, the value of USDC deposited is enough to match with each constituent asset in the index. After each index asset has been matched with base assets the two sides can be deposited into their respective liquidity pool.
A worked example will clarify this further. Let’s assume that an investor wants to deposit 100 USDC into the ETH/LINK index which is weighted 50:50. The price of the USDC/LINK swap is 0.1 and the price of the USDC/ETH swap is 0.0025. For simplicity we will assume no fees and no change in prices after the swap is made.
- USDC is converted into constituent assets: 5 LINK and 0.125 ETH.
- A liquidity provider deposits USDC into the USDC/LINK and USDC/ETH matching pools respectively in a ratio of 100:0. Each pool receives 100 USDC.
- Each index asset is worth 50 USDC and therefore must be matched with an equivalent 50 USDC.
- 50 USDC / 5 LINK is deposited into the USDC/LINK pool and 50 USDC / 0.125 ETH is deposited into the USDC/ETH pool.
- Astute readers will notice that there remains 50 USDC unaccounted for in both liquidity pools. This USDC will remain in its respective matching pools until matched with quote assets from new index minters.
Fast forwarding time, the index holder now wants to redeem his m-tokens for USDC. The swap price for USDC/LINK and USDC/ETH is now 0.2 and 0.002 respectively. Therefore, the index holder can withdraw 8.75 LINK and 0.0875 ETH.
6. Index redemption is initiated and 8.75 LINK and 0.0875 ETH are withdrawn from the liquidity pools along with an equal amount of USDC.
7. The withdrawn USDC goes back into the matching pool waiting to be coupled with the next balance of quote assets from new index minters.
8. The withdrawn LINK and ETH are then swapped for 43.75 USDC each, for a total of 87.5 USDC. Alternatively, the index holder has the option to receive each constituent asset and so in this case, the 8.75 LINK and 0.0875 ETH would be sent directly to the index holder’s wallet.
In summary, the matching system acts as the gateway for index minters into PhutureDAO’s liquidity pools. The provision of index assets into liquidity pools is critical for ensuring that the protocol can effectively rebalance index portfolios. Moreover, the matching system provides a flexible onramp for supplying unbalanced liquidity to the protocol, and removes the slippage incurred by other platforms offering one sided liquidity.