The Moola Router automatically wraps and/or unwraps cUSD/cEUR/CELO into mcUSD/mcEUR/mCELO. It allows users to have an identical user experience to the traditional router while allowing for significantly less slippage when trading Moola assets.
We built the Moola Router in order to maximize the liquidity within Celo's early DeFi ecosystem. We want to ensure that there are always enough tokens for users to borrow, as being able to borrow allows long-term Celo holders to participate in DeFi farming without selling.
There is one deployed contract: MoolaRouter, which implements the swapExactTokensForTokens and swapTokensForExactTokens functions. A MoolaRouter user will specify the trading path, and if the first two or last two tokens of the path are "Moola duals", i.e. the tokens can be converted to/from each other via deposit or withdrawal, then the trade will route via the Moola LendingPool contract.
The swap functions perform the following steps:
Record all balances on the router.
Construct a "Swap Plan" to figure out which parts of the path will use Moola to route
If the Swap Plan determined that part of the route should go to the UbeswapRouter, approve the UbeswapRouter for the amount desired
Transfer the input tokens from the sender
If there is a Moola route for the first two tokens, withdraw or deposit.
If the UbeswapRouter has a path, perform the swap.
If there is a Moola route for the last two tokens, withdraw or deposit.
Check to see that the output balances are equal to the input balances, other than the final output token. Unless the output token is equivalent to a token in the path, or the token is the input token.
Transfer the output tokens to the _to address.
There is a contract owner on the Moola Router that can withdraw any stuck tokens. This is currently set to the "Operator" address but will be transitioned to the Executive Timelock if there are no issues.