Goal

  • Manipulation Resistance: The architecture of the rollup and related systems themselves already has safeguards in place to prevent various forms of manipulation from malicious actors. The Minitswap DEX is further designed to ensure that, in unforeseen events, any subsequent damages are minimized.
  • Capital Efficiency: As the number of rollups continue to increase, naively, the same number of DEX pairs must also exists. This results in liquidity fragmentation, high slippage and volatility, and subpar user experience.

Design

Minitswap itself is designed as a virtual pool DEX between and the various tokens for each of the rollups. The exchange rates on each swap are determined by the StableSwap formula.

To achieve the above goals, two main improvements are made to the base StableSwap pool design:

  • Rate Limiting: To protect against manipulation, the net amount of IbcOpINIT tokens that can be swapped back into INIT tokens is limited. This means that even if a malicious actor manages to acquire or create a large amount of IbcOpINIT tokens on their rollup, the number of tokens that can be swapped back into regular INIT tokens remains restricted.
  • Single INIT Token Pool: To minimize liquidity fragmentation, there is a single INIT token pool that can be paired with multiple IbcOpINIT token pools, instead of having separate INIT token pools for each rollups.

Swap Mechanisms

Initia L1 to Rollups

Initia L1 to Rollups Minitswap Flow

In this scenario, a user wants to efficiently bridge their INITINIT tokens on the Initia L1 to a rollup mm and ends up with the OpINITmOpINIT_m token for that rollup.

And while bridging from Initia L1 to a rollup is instantaneous, users may occasionally be able to obtain a more favorable rate by utilizing Minitswap as part of the bridging process as shown below.

  1. Initiate Swap on Minitswap DEX: The user sends a transaction to the Minitswap DEX to swap their INITINIT tokens into IbcOpINITmIbcOpINIT_m tokens.
  2. Simulate Swap: The DEX simulates swapping the user’s INITINIT tokens into IbcOpINITmIbcOpINIT_m tokens.
  3. Compare Swap and Direct Bridging: The DEX compares the simulated amount of IbcOpINITmIbcOpINIT_m tokens with the amount the user would receive if they bridged directly through the OP Bridge.
  4. Perform Optimal Action
    • If the amount of IbcOpINITmIbcOpINIT_m tokens from the swap is greater, the DEX performs the swap. The output IbcOpINITmIbcOpINIT_m tokens are then bridged to the destination L2 through IBC.
    • If the direct bridging through the OP bridge provides a better amount, the DEX initiates a direct transfer to the destination rollup mm for the user using the OP bridge.
  5. Minitswap Swap Process
    • Calculate IbcOpINITmIbcOpINIT_m Received: Minitswap calculates how much IbcOpINITmIbcOpINIT_m the user will receive based on the current Virtual Pool state, updating the state in the process.
    • Fee Deduction: Minitswap deducts a fee based on a predefined value and an additional fee from any extra IbcOpINITmIbcOpINIT_m that the user receives.
    • Peg Keeper Swap Check: Once the user’s swap action and fee calculation are complete, Minitswap checks if a Peg Keeper Swap should be performed based on the latest Virtual Pool state.
    • Internal Rebalancing Check: After completing the Peg Keeper Swap, Minitswap checks if Internal Rebalancing is possible based on the Peg Keeper’s IbcOpINITIbcOpINIT balance. If balancing is possible, it is initiated.
  6. Final Outcome: In both cases, once the OP Bridge or IBC transfer is complete, the user receives the most amount of OpINITmOpINIT_m tokens in their wallet on the destination rollup possible.

Rollup to Initia L1

Rollup to Initia L1 Minitswap Flow

When bridging from a rollup to Initia L1, the user is currently holding OpINITmOpINIT_m tokens on a rollup mm and would like to bridge it back to INITINIT tokens on the Initia L1.

In this scenario, utilizing Minitswap will enable them to bridging their INIT back to the Initia L1 instantaneously without waiting for the challenge period to expire.

  1. Transfer to Initia L1 via IBC: The user begins by transferring their OpINITmOpINIT_m tokens on the rollup mm back to Initia L1 using IBC. As a result, they receive IbcOpINITmIbcOpINIT_m tokens on the Initia L1.
  2. Swap on Minitswap DEX: Once the IBC transfer is complete and the user has IbcOpINITmIbcOpINIT_m tokens on Initia L1, they initiate a swap transaction on the Minitswap DEX to convert their IbcOpINITmIbcOpINIT_m tokens into INITINIT tokens.
  3. Minitswap Swap Process
    • Peg Keeper Swap Check: Minitswap first checks if a Peg Keeper Swap can be performed. If this is possible, the swap is executed directly through the Peg Keeper.
    • Calculate INITINIT Received: If the Peg Keeper Swap is not applicable, Minitswap calculates the amount of INITINIT the user will receive based on the updated state of the Virtual Pool.
    • Fee Deduction: Minitswap deducts a predefined fee amount from the transaction.
    • Internal Rebalancing Check: After completing the user’s swap transaction, Minitswap checks if Internal Rebalancing is possible based on the Peg Keeper’s IbcOpINITIbcOpINIT balance. If balancing is possible, it is executed to maintain market stability.
  4. Final Outcome: If the swap is successful, the user receives INITINIT tokens in their wallet on Initia L1.

Direct Swap

In addition to the standard directional swap explained above, Minitswap also offers a unique Direct Swap option. As more Peg Keeper Swaps are performed, the Peg Keeper’s INITINIT balance decreases. The Direct Swap aims to incentivize users to help replenish the Peg Keeper’s INITINIT token balance, which gets depleted over time. This serves as an additional method of replenishing the Peg Keeper’s INITINIT balance alongside the Internal Rebalancing.

The Direct Swap allows any user to directly exchange their INITINIT tokens for the Peg Keeper’s IbcOpINITIbcOpINIT tokens. This exchange occurs at the average price at which the Peg Keeper has purchased INITINIT tokens, which could sometimes be lower than the price obtained through the traditional swap process. Initially, the Direct Swap might not seem attractive due to the Target Ratio being close to 0.5. However, as the Peg Keeper’s balance of OP-bridged tokens increases, the Direct Swap option becomes more appealing to users.

Swap Logic

Parameters

  • Max Ratio: The Max Ratio, RmaxR_{max}, is a Initia L1 governance-controlled parameter that dictates the maximum pool ratio between IbcOpINIT and regular INIT

  • Fully Recovered Ratio: The Fully Recovered Ratio, RfrR_{fr} then uses the Max Ratio and the Flexibility to calculate the final target IbcOpINIT:INIT ratio for the pool. The ratio is calculated as follows

Rfr=0.5+(Rmax0.5)(fI)3(1+fI3)R_{fr}=0.5+(R_{max}-0.5) \cdot \frac{(fI)^3}{(1+|fI|^3)}

Mechanisms

Peg Keeper Swaps

Peg Keeper Swaps

The Peg Keeper Swap is a mechanism designed to keep the exchange rate between INITINIT and IbcOpINITIbcOpINIT close to 1:1. This ensures that users always receive the best swap rates.

When users move their INIT tokens from a rollup back to Initia L1 using Minitswap, they are essentially selling their IbcOpINITIbcOpINIT tokens for INITINIT tokens. As more users do this, the supply of IbcOpINITIbcOpINIT increases relative to INITINIT, which raises the price of future rollup -> Initia L1 swaps.

To address this, the Peg Keeper Swap executes a (INITINIT -> IbcOpINITIbcOpINIT) swap to balance the effect. When a user makes a swap, Minitswap checks the Fully Recovered Ratio against the current pool ratio. If the current ratio exceeds the Fully Recovered Ratio, a Peg Keeper Swap is triggered to restore balance.

When run, the Peg Keeper swap follows the following procedure:

  1. Calculate the current RfrR_{fr} and the max_recover_amount, which defines the maximum size of the Peg Keeper Swap that can be performed in this swap. This is to prevent a huge Peg Keeper Swap from happening.
  2. Check if another Peg Keeper Swap has been run in the same block. Continue if no swaps have been run.
  3. Calculate the INITINIT amount the Peg Keeper needs to reach RfrR_{fr}. Let’s call this swap_amount_to_reach_fr.
  4. Check if swap_amount_to_reach_fr > max_recover_amount
    • If true, swap only max_recover_amount.
    • If false, swap swap_amount_to_reach_fr

Note that the Peg Keeper Swap check is done

  • before a L2 -> L1 swap to make sure the user gets the best rate possible
  • after a L1 -> L2 swap to make sure the user’s swap rate doesn’t get affected by the Peg Keeper Swap

Internal Rebalancing

Internal Rebalancing

As more Peg Keeper Swaps are performed, the INITINIT balance of the Peg Keeper gradually decreases. To replenish its INITINIT balance, the system has an internal rebalancing procedure that converts the Peg Keeper’s IbcOpINITIbcOpINIT back into INITINIT using IBC and OP Bridge.

The rebalancing process follows these steps:

  1. Bridge the Peg Keeper’s IbcOpINITmIbcOpINIT_m back to the rollup mm using IBC, converting it into OpINITmOpINIT_m.
  2. Use the OP Bridge to convert OpINITmOpINIT_m back into INITINIT.

This process, combined with the Direct Swap, ensures that the Peg Keeper’s INITINIT balance is replenished, allowing it to continue performing Peg Keeper Swaps.