Minitswap
Overview
Minitswap is a virtual pool dex based on the StableSwap, protocol designed to alleviate the inconvenience caused by the withdraw period of the OP bridge.
Issues with the OP bridge in Omni-chain
Transfering tokens from L1 to L2 via the OP bridge is straightforward and immediate, but returning from L2 to L1 is not as simple. You must wait for the withdrawal period, and this lack of immediacy poses the most significant challenge in Interchain messaging.
Therefore, to achieve immediate withdrawal, user need to use DEX pair with origin token and op bridged token. However, the operability of a single sequencer in L2 creates apprehension to liquidity provider, ultimately leading users to face high costs due to low liquidity, high volatility and slippage.
Objectives of Minitswap
What we want to achieve from Minitswap
Protection against manipulation: Of course, since for whitelisted Minitia only designated person can act as relayers, even if operator create OP bridged token, it is nearly impossible transfer tokens to L1. However, we cannot guarantee that such accidents will not occur, so efforts are needed to minimize damage.
Capital efficiency: If there are numerous Minitias, a corresponding number of pairs must exist. This inevitably leads to liquidity dispersion, resulting in high slippage and cost
How Minitswap solve these problems
To protect against manipulation, the net amount of tokens that swapped OP bridged token into origin token in a specific period is limited, and if necessary, the pool can be deactivated using the L1’s emergency poll.
Addressing liquidity dispersion can be achieved by allowing multiple OP bridged tokens to exchange with a single origin token pool. This implementation, as virtual pools, can yield higher liquidity effects compared to the presence of numerous actual pairs for each.
Key Concepts
Depositor
The Depositor provides liquidity for the origin token and earns swap fees, unlike typical DEXs, it does not provide the opposing token (in this case, OP bridge token). This is possible because Minitswap does not allow the OP bridge token to decrease relative to the origin token within the virtual pool. As a result, it allows the Depositor to achieve twice the liquidity effect with half the assets.
Virtual Pool
As you can see from the Depositor, the structure is different from a typical DEX. Initially, when the pool size is Z, it starts with a virtual OP bridged token of Z and a virtual origin token amount of Z. The exchange rate is determined by the stable swap formula, and virtual pool does not allow the number of OP bridged tokens to be less than Z. (In this situation, using OP bridge is better option to them.) During the swap process, the origin tokens are taken from or filled into the deposit pool.
Peg Keeper
The Peg Keeper is a virtual market participant that swaps the origin token for OP bridged tokens, aiming to maintain a price close to 1:1 between the origin token and the OP bridged token.
Ultimately, the net amount of tokens swapped from OP bridged tokens into origin tokens in a specific period is restricted by the sum of the current origin tokens remaining in the virtual pool plus the amount the Peg Keeper swaps for origin tokens during that period. (The later one is set as a virtual pool config)
The Peg Keeper always swaps before user swaps, creating an effect where it purchases OP bridged tokens at a lower price than those wanting to buy OP bridged token cheaply. Simultaneously, it offers a better price to those looking to convert OP bridged tokens into origin tokens.
Target Ratio
The Target Ratio is the ratio that peg keeper's desired proportion of OP bridged tokens in virtual pool. For example, if the Target Ratio is 0.6, it means the ratio of OP bridged tokens to origin tokens in the virtual pool is 6:4. This is adjusted based on the balance of OP bridged tokens that owned by the Peg Keeper, with the Target Ratio increasing as the balance of OP bridged tokens grows.
Direct Swap
Through Direct Swap, user can directly swap the OP bridged tokens that Peg Keeper holds at the average price it has purchased them so far. While initially, Direct Swap may not be attractive due to the Target Ratio being close to 0.5, as the balance of OP bridged tokens held by the Peg Keeper increases, Direct Swap becomes more attractive. This serves the role of reclaiming the origin tokens used by the Peg Keeper over time.
Target Ratio(R_t) Calculation
Definition
Virtual Pool Size (Z): When the pool ratio becomes 5:5, the amounts for each become Z, and this Z is defined as the pool size.
Peg Keeper’s balance of OP bridged token (B)
Imbalance (I = Z/B): Imbalance indicates how far the current virtual pool deviates from its initial state
Max Ratio (R_max): Maximum value of Target Ratio
Flexibility (f): Flexibility refers to the adaptability of Imbalance. A higher flexibility means that a low target ratio can be maintained even with a high imbalance
Formula
Low Flexibility VS High Flexibility
Blue: Max Ratio (0.7)
Green: 0.5
Purple: with f = 2
Red: with f = 0.5
Changing Pool Size
The Pool size needs to be changed based on the activity level of Minitia. The current process for changing the Pool size is as follows:
Increasing process
Peg Keeper swap origin token → OP bridged token until pool ratio become 5:5
Increase pool size
Peg Keeper Swap back OP bridged token → origin token (the swap amount is same as return amount of 1.)
Net Result
Balance of Peg Keeper: OP bridge token balance does not change and origin token balance increases.
Ratio of Pool: Decreasing of OP Bridged token price
Decreasing process
Change pool amount in same amount ratio (ex: 400:200 → 300:150)
Calculate diff and adjust it to peg keeper’s balances
Net Result
Balance of Peg Keeper: origin token balance decreases and OP bridged token balance increases. But always increasing balance is higher than decreasing balance. (This means it is same as that Peg Keeper swap origin token to OP bridged token)
Ratio of Pool: Doesn’t change
Extend pool
To create a virtual pool and to change the pool size, it need to pass governance proposal. To compensate for this inflexibility, l2 operator can generate permissionless extend pool. This pool is based on 0x1::stableswap
and anyone can create.
Default swap process
If there is only one stable swap pair or virtual pool, swap the one with exists
If there are both stable swap pair and virtual pool, simulate both pool and use the one that give greater amount
Last updated