# Minitswap
## Overview
Minitswap is Initia's proprietary solution to address the user experience challenges posed by the lengthy withdrawal challenge periods of optimistic bridges. Furthermore, while setting the period to a logner timeframe increases the duration in which a challenge can be made, it simultaneously increases the wait time required for withdrawals.
## Motivation
While optimistic token bridges between a Layer 1 (L1) and a Layer 2 (L2) chain provides a secure way of transferring assets between chains, it comes with various downsides
- **Long Withdrawal Times**: Transferring tokens from L1 to L2 is usually instantaneous, but the reverse direction involves long wait times, often days, before receiving assets on L1.
- **Singe Sequencer Risks**: Creating a DEX pair between the original token on L1 and the bridged tokens can mitigate long withdrawal times. However, most L2s currently operate with a single sequencer, raising security, reliability, and centralization concerns for liquidity providers.
- **Lack of Liquidity**: These issues can result in insufficient liquidity in the token pool, leading to unfavorable swap prices, high volatility, and significant slippage for users bridging tokens back to L1.
## Goal
- **Manipulation Resistant**: The architecture of the minitia and related systems themselves already has safegaurds in place to prevent various forms of manipulation from malicious actors. The Minitswap DEX is further designed to ensure that, in any unforseen events, any subsequent damages are minimized
- **Capital Efficiency**: As the number of minitias continue to increase, naively, the same number of DEX pairs must also exists. This results to liquidity fragmentation, high slippage and volatility, and subpar user experience.
## Design
Minitswap itself is designed as a virtual pool DEX between $INIT$ and the various $IbcOpINIT_m$ tokens for each of the minitias. The exchange rates on each swap is determined by the StableSwap formula.
To achive the above goal, two main improvements are made to the base design:
- **Rate Limiting**: To protect against manipulation, the net amount of $IbcOpINIT$ tokens that can be swapped back into INIT tokens
- **Single INIT Token Pool**. To minimize liquidity fragmentation, a single INIT token pool that can be paired with multiple $IbcOpINIT$ tokens, instead of having separate INIT token pools for each minitia.
## End User Flow
### L1 to L2
In this case, the user wants to efficiently bridge their INIT tokens on the Initia L1 to a minitia $m$ and ends up with the $OpINIT_m$ token for that minitia.
1. The user sends a transaction to the Minitswap DEX to swap their $INIT$ into $IbcOPINIT_m$
2. The DEX simulates swapping the user’s $INIT$ tokens into $IbcOpINIT_m$ tokens.
3. The DEX compares the simulated amount of $IbcOpINIT_m$ tokens with the amount the user would get if they bridged directly through the OP bridge.
4. If the amount of $IbcOpINIT_m$ tokens from the swap is greater:
- The DEX performs the swap.
- The output $IbcOpINIT_m$ tokens are then bridged to the destination L2 through IBC.
5. If the direct bridging through the OP bridge gives a better amount, the DEX initiates a direct transfer to the destination minitia for the user using the OP bridge.
6. In both cases, once the OP Bridge or IBC transfer completes, the user now have $OpINIT_m$ tokens on in their wallet on the destination minitias
### L2 to L1
In this case, the user is currently holding $OpINIT_m$ tokens on a minitia L2 $m$ and would like to bridge it back to $INIT$ tokens on the L1.
1. The user first transfers their $OpINIT_m$ token on the minitia L2 back to the Initia L1 thrugh IBC, receiving $IbcOPINIT_m$
2. Once their IBC transfer is complete, they then send a swap transaction to the Minitswap DEX to convert their $IbcOpINIT_m$ back into vanilla INIT
3. If the swap is successful, they now received $INIT$ in their wallet
## Terminology
**INIT Token Variants**
| Term | Definition |
|-----------------|----------------------------------------------------------------------------------------------------------|
| $INIT$ | The vanilla Initia INIT tokens on the Initia L1 |
| $m$ | The destination minitia that the user wants to bridge to |
| $OpINIT_m$ | The variation of the INIT tokens bridged directly from the Initia L1 to the destination minitia $m$ |
| $IbcOpINIT_m$ | The variation of the INIT token that was bridged from Initia L1 to the minitia $m$ through OP Bridge, then subsequently back to the L1 through IBC |
**Bridges**
| Term | Description |
|-----------------|-----------------------------------------------------------------------------------------------------|
| IBC Bridge | The Inter-Blockchain Communication Protocol used as a bridging solution between minitias. Bridging in both directions are instantaneous. |
| OPINIT Bridge | Initia's implementation of an optimistic bridge to be used as the primary bridge between the Initia L1 and all minitias. Deposits into minitias are instantaneous but withdrawals have a waiting period.|