Swapping

Creating a swap

The swapping UI looks like this:

openSwap currently supports swapping ETH <-> USDC. Choose the amount you want to sell and hit Create Swap. After this point, the user typically does not have to do anything and will receive their tokens back after a short wait.

Order submitted

When a swap is created, an order is submitted, and you will see the below:

At the submission stage, orders can be cancelled until someone matches - there will be a red cancel button next to Order Submitted until this point. The fulfillment fee (fee paid to the matcher) starts at 0.0075% and increases over time until matched. The max fulfillment fee is currently set to 0.02%.

Order matched

Once your order submission has been matched, you will see the following:

Here, the fulfillment fee was 0.011%. At this point, you are waiting for an initial report in the oracle game. If an initial report has not been submitted within 30 seconds of this step (default but configurable), a Bail Out button will appear, which refunds the swapper and effectively cancels the swap. Once an initial report is on-chain, the oracle game begins where a network of MEV bots ensures you get fair pricing.

Oracle game

While the swapper doesn't have to play the oracle game to swap, the steps of the game are exposed in the UI:

This is the permissionless escalation game step, where the execution price is determined by the final ratio of token balances in the oracle game. Each challenge (dispute) requires increasing token commitments. During this openSwap order, the price changed, so it was profitable for a disputer to step in and correct the initial report's price. The settlement step is typically handled by MEV bots. 4 seconds after the most recent report or dispute, the oracle game becomes settle-able. If an MEV bot does not pick up the settle, the UI exposes a green Settle button for the user to call. Once settled, the swap either executes using the final price ($2792.94 here) or refunds the swapper and matcher their original amounts. Refunds happen when the execution price is outside the slippage tolerance passed by the swapper. The 4 second parameter (called the settlement time) is a default value but is configurable in the advanced settings. Generally, you want a short settlement time for the most accurate execution price.

Swap executed

In the same step as the settle, if the oracle game price was inside slippage tolerance, the swap will execute. If the price is outside slippage tolerance, the swapper and matcher will be refunded their original amounts. The UI exposes all components of the fees:

Advanced Settings

The UI exposes some advanced settings to the user:

Expiration is how much time you must wait after an order is matched to cancel and get your tokens back, assuming nobody has yet reported a price (oracle game has not started). Slippage is how much the price can move between order submission and execution. If the execution price is outside your slippage tolerance, you are refunded your original amounts. Slippage is automatically calculated by the UI as a multiple of prevailing market volatility to ensure a high probability of success while keeping it as small as possible to reduce possible losses. Settler reward is how much ETH is paid to the MEV bot that eventually settles the oracle game and executes the transaction. Since this is just the cost of ~500k gas, it is generally very cheap especially on Optimism. The UI automatically calculates the appropriate settler reward based on prevailing gas prices. Settlement time is the per-round timer on the oracle game. If a reported price isn't disputed in this amount of time, the report is considered valid and can be used to execute the openSwap order. Generally, you want this number to be low. With higher settlement times, the final price becomes less accurate. There is a square root relationship: if the settlement time were 16 seconds instead of 4, the oracle would be ~2x less accurate ( sqrt(16/4) ) than that of 4 seconds, and you as a swapper would need to wait longer to get your tokens back. Longer settlement times may be more appropriate for large swap amounts as they allow more time for the MEV bot network to move funds and react to any badly priced reports. Initial liquidity is the starting oracle game liquidity. This number is automatically calculated by the UI and will be the larger of 10% of swap size or the amount that makes gas fees to correct bad prices less than 0.01% of the initial liquidity. If you set your initial liquidity too low relative to prevailing gas fees, it becomes easier to get a bad price through the oracle game. Too high, and it increases the swap expenses, since you have to pay the provider of initial liquidity a bounty to play the oracle game. It is recommended to use the default initial liquidity the UI provides. Max bounty is the maximum the swapper can pay the provider of initial liquidity in the oracle game (the initial reporter). The bounty starts low and increases over time until the first MEV bot deems it valuable enough to claim. The UI calculates this based on a number of factors to include prevailing market volatility. It is recommended to let the UI calculate this number unless you know what you are doing. Delay mode is defaulted to off. When this setting is on, there is a small fee applied to each dispute in the oracle game. Since each round in the oracle game is exponentially larger than the previous round, any meaningful delay accrues a large amount of fees. These fees are routed back to the swapper and matcher at swap execution to ensure users are more than compensated for material delay. Adding a small fee to the oracle game decreases oracle accuracy (worsening swap execution) so it is recommended to leave this setting off unless there's a lot of oracle network activity.

Last updated