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 continues to increase,
naively, the same number of DEX pairs must also exist. This results in
liquidity fragmentation, high slippage and volatility, and subpar user
experience.
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 rollup.
In this scenario, a user wants to efficiently bridge their INIT tokens on the
Initia L1 to a rollup m and ends up with the OpINITm 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 INIT tokens into IbcOpINITm tokens.
Simulate Swap: The DEX simulates swapping the user’s INIT tokens into
IbcOpINITm tokens.
Compare Swap and Direct Bridging: The DEX compares the simulated amount
of IbcOpINITm tokens with the amount the user would receive if they
bridged directly through the OP Bridge.
Perform Optimal Action
If the amount of IbcOpINITm tokens from the swap is greater, the DEX
performs the swap. The output IbcOpINITm 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 m for the user
using the OP bridge.
Minitswap Swap Process
Calculate IbcOpINITm Received: Minitswap calculates how much
IbcOpINITm 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 IbcOpINITm 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 IbcOpINIT 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 OpINITm tokens in their
wallet on the destination rollup possible.
When bridging from a rollup to Initia L1, the user is currently holding
OpINITm tokens on a rollup m and would like to bridge it back to INIT
tokens on the Initia L1.In this scenario, utilizing Minitswap will enable them to bridge 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
OpINITm tokens on the rollup m back to Initia L1 using IBC. As a result,
they receive IbcOpINITm tokens on the Initia L1.
Swap on Minitswap DEX: Once the IBC transfer is complete and the user has
IbcOpINITm tokens on Initia L1, they initiate a swap transaction on the
Minitswap DEX to convert their IbcOpINITm tokens into INIT 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 INIT Received: If the Peg Keeper Swap is not applicable,
Minitswap calculates the amount of INIT 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 IbcOpINIT balance. If balancing is possible, it is executed to
maintain market stability.
Final Outcome: If the swap is successful, the user receives INIT tokens
in their wallet on Initia L1.
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 INIT
balance decreases. The Direct Swap aims to incentivize users to help replenish
the Peg Keeper’s INIT token balance, which gets depleted over time. This
serves as an additional method of replenishing the Peg Keeper’s INIT balance
alongside the Internal Rebalancing.The Direct Swap allows any user to directly exchange their INIT tokens for the
Peg Keeper’s IbcOpINIT tokens. This exchange occurs at the average price at
which the Peg Keeper has purchased INIT 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.
Max Ratio: The Max Ratio, Rmax, is an Initia L1 governance-controlled
parameter that dictates the maximum pool ratio between IbcOpINIT and regular
INIT
Fully Recovered Ratio: The Fully Recovered Ratio, Rfr 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
The Peg Keeper Swap is a mechanism designed to keep the exchange rate between
INIT and IbcOpINIT 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 IbcOpINIT tokens for INIT
tokens. As more users do this, the supply of IbcOpINIT increases relative to
INIT, which raises the price of future rollup -> Initia L1 swaps.To address this, the Peg Keeper Swap executes a (INIT -> IbcOpINIT) 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 Rfr 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 INIT amount the Peg Keeper needs to reach Rfr. 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
Note that the Peg Keeper Swap check is done
before an L2 -> L1 swap to make sure the user gets the best rate possible
after an L1 -> L2 swap to make sure the user’s swap rate doesn’t get
affected by the Peg Keeper Swap
As more Peg Keeper Swaps are performed, the INIT balance of the Peg Keeper
gradually decreases. To replenish its INIT balance, the system has an internal
rebalancing procedure that converts the Peg Keeper’s IbcOpINIT back into
INIT using IBC and OP Bridge.The rebalancing process follows these steps:
Bridge the Peg Keeper’s IbcOpINITm back to the rollup m using IBC,
converting it into OpINITm.
Use the OP Bridge to convert OpINITm back into INIT.
This process, combined with the Direct Swap, ensures that the
Peg Keeper’s INIT balance is replenished, allowing it to continue performing
Peg Keeper Swaps.