Minitswap Architecture
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 tokens on the Initia L1 to a rollup and ends up with the 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.
- Initiate Swap on Minitswap DEX: The user sends a transaction to the Minitswap DEX to swap their tokens into tokens.
- Simulate Swap: The DEX simulates swapping the user’s tokens into tokens.
- Compare Swap and Direct Bridging: The DEX compares the simulated amount of tokens with the amount the user would receive if they bridged directly through the OP Bridge.
- Perform Optimal Action
- If the amount of tokens from the swap is greater, the DEX performs the swap. The output 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 for the user using the OP bridge.
- Minitswap Swap Process
- Calculate Received: Minitswap calculates how much 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 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 balance. If balancing is possible, it is initiated.
- Final Outcome: In both cases, once the OP Bridge or IBC transfer is complete, the user receives the most amount of 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 tokens on a rollup and would like to bridge it back to 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.
- Transfer to Initia L1 via IBC: The user begins by transferring their tokens on the rollup back to Initia L1 using IBC. As a result, they receive tokens on the Initia L1.
- Swap on Minitswap DEX: Once the IBC transfer is complete and the user has tokens on Initia L1, they initiate a swap transaction on the Minitswap DEX to convert their tokens into tokens.
- 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 Received: If the Peg Keeper Swap is not applicable, Minitswap calculates the amount of 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 balance. If balancing is possible, it is executed to maintain market stability.
- Final Outcome: If the swap is successful, the user receives 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 balance decreases. The Direct Swap aims to incentivize users to help replenish the Peg Keeper’s token balance, which gets depleted over time. This serves as an additional method of replenishing the Peg Keeper’s balance alongside the Internal Rebalancing.
The Direct Swap allows any user to directly exchange their tokens for the Peg Keeper’s tokens. This exchange occurs at the average price at which the Peg Keeper has purchased 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, , 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, 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
Mechanisms
Peg Keeper Swaps
Peg Keeper Swaps
The Peg Keeper Swap is a mechanism designed to keep the exchange rate between and 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 tokens for tokens. As more users do this, the supply of increases relative to , which raises the price of future rollup -> Initia L1 swaps.
To address this, the Peg Keeper Swap executes a ( -> ) 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:
- Calculate the current 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. - Check if another Peg Keeper Swap has been run in the same block. Continue if no swaps have been run.
- Calculate the amount the Peg Keeper needs to reach . Let’s call this
swap_amount_to_reach_fr
. - 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
- If true, swap only
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 balance of the Peg Keeper gradually decreases. To replenish its balance, the system has an internal rebalancing procedure that converts the Peg Keeper’s back into using IBC and OP Bridge.
The rebalancing process follows these steps:
- Bridge the Peg Keeper’s back to the rollup using IBC, converting it into .
- Use the OP Bridge to convert back into .
This process, combined with the Direct Swap, ensures that the Peg Keeper’s balance is replenished, allowing it to continue performing Peg Keeper Swaps.
Was this page helpful?