MIMSwap
Overview
MIMSwap is a decentralized automated market maker (AMM) designed for creating and managing liquidity pools. This documentation provides a detailed guide on the MIMSwap Router, MagicLP liquidity pools, and integration steps for third-party applications. MIMSwap is based off of Dodo DSP v2, complementary information can be found in Dodo's documentation.
MagicLP Liquidity Pools
Introduction
MagicLP liquidity pools are the core components of the MIMSwap system. They facilitate token swaps, liquidity provision, and yield generation. This section focuses on the MagicLP contract, detailing how it works, how to interact with it directly, and how the MIMSwap Router leverages its functionalities.
Key Functions in MagicLP
Swapping Tokens
sellBase
sellQuote
Adding Liquidity
buyShares
Removing Liquidity
sellShares
Query Functions
querySellBase
querySellQuote
Swapping Tokens
sellBase
This function sells base tokens (e.g., MIM) for quote tokens (e.g., USDC).
Process:
Balance Calculation: Calculates the base tokens received.
Query: Uses
querySellBase
to determine the amount of quote tokens to send in return.Transfer: Transfers the calculated quote tokens to the recipient.
Update Reserves: Updates the pool reserves.
Example Usage:
sellQuote
This function sells quote tokens (e.g., USDC) for base tokens (e.g., MIM).
Process:
Balance Calculation: Calculates the quote tokens received.
Query: Uses
querySellQuote
to determine the amount of base tokens to send in return.Transfer: Transfers the calculated base tokens to the recipient.
Update Reserves: Updates the pool reserves.
Example Usage:
Adding Liquidity
buyShares
This function allows users to provide liquidity to the pool in exchange for LP tokens.
Process:
Balance Calculation: Calculates the base and quote tokens added to the pool.
Share Calculation: Determines the number of LP tokens to mint based on the input tokens.
Minting: Mints the LP tokens and sends them to the specified address.
Update Reserves: Updates the pool reserves.
Example Usage:
Removing Liquidity
sellShares
This function allows users to redeem their LP tokens for the underlying base and quote tokens.
Process:
Share Calculation: Determines the amount of base and quote tokens to return based on the LP tokens being redeemed.
Transfer: Transfers the base and quote tokens to the specified address.
Burning: Burns the redeemed LP tokens.
Update Reserves: Updates the pool reserves.
Example Usage:
Query Functions
querySellBase
Returns the amount of quote tokens received for selling a specified amount of base tokens.
Usage:
querySellQuote
Returns the amount of base tokens received for selling a specified amount of quote tokens.
Usage:
Example: Using the Router to Interact with MagicLP
While the MagicLP contract provides all the necessary functions for token swaps and liquidity operations, the MIMSwap Router simplifies these interactions by providing a unified interface. Let's walk through an example of how the Router interacts with the MagicLP pools to perform a token swap.
Step-by-Step Swap Example Using the Router
Determine the Path and Directions
Assume we want to swap MIM for USDC through a single liquidity pool.
Get the Expected Price
Use the
querySellBase
function to get the expected amount of USDC for the given amount of MIM.Execute the Swap
Call the
swapTokensForTokens
function on the router with the determined path and directions.
By following these steps, third-party systems can effectively integrate MIMSwap's swapping functionality, providing their users with seamless and efficient token swaps.
Last updated