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

  1. Swapping Tokens

    • sellBase

    • sellQuote

  2. Adding Liquidity

    • buyShares

  3. Removing Liquidity

    • sellShares

  4. Query Functions

    • querySellBase

    • querySellQuote

Swapping Tokens

sellBase

This function sells base tokens (e.g., MIM) for quote tokens (e.g., USDC).

Process:

  1. Balance Calculation: Calculates the base tokens received.

  2. Query: Uses querySellBase to determine the amount of quote tokens to send in return.

  3. Transfer: Transfers the calculated quote tokens to the recipient.

  4. Update Reserves: Updates the pool reserves.

Example Usage:

sellQuote

This function sells quote tokens (e.g., USDC) for base tokens (e.g., MIM).

Process:

  1. Balance Calculation: Calculates the quote tokens received.

  2. Query: Uses querySellQuote to determine the amount of base tokens to send in return.

  3. Transfer: Transfers the calculated base tokens to the recipient.

  4. 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:

  1. Balance Calculation: Calculates the base and quote tokens added to the pool.

  2. Share Calculation: Determines the number of LP tokens to mint based on the input tokens.

  3. Minting: Mints the LP tokens and sends them to the specified address.

  4. 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:

  1. Share Calculation: Determines the amount of base and quote tokens to return based on the LP tokens being redeemed.

  2. Transfer: Transfers the base and quote tokens to the specified address.

  3. Burning: Burns the redeemed LP tokens.

  4. 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

  1. Determine the Path and Directions

    Assume we want to swap MIM for USDC through a single liquidity pool.

  2. Get the Expected Price

    Use the querySellBase function to get the expected amount of USDC for the given amount of MIM.

  3. 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