Skip to main content

Creating a swap

The swapping UI looks like this: openSwap V2 currently supports swapping ETH ↔ USDC on Base. 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 canceled until someone matches. The fulfillment fee paid to the matcher starts at the configured starting fee and increases over time until the swap is matched or the configured cap is reached.

Order matched

Once your order submission has been matched, you will see the following: The matcher creates the oracle game and submits the initial report in the same matchSwap() transaction. Once the swap is matched, the oracle game is already live and can be disputed or settled. If the swap is not executed within the configured max game time after match, a Bail Out path is available that refunds the swapper and matcher their original amounts.

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 an openSwap order, the price may change, so it may be profitable for a disputer to step in and correct the matcher’s initial price. The execution step is typically handled by MEV bots. After the most recent report or dispute sits undisputed for the configured settlement time, the oracle game becomes settleable and the swap becomes executable. The executor calls execute(), which settles the oracle inline if needed and either fulfills the swap at the final price or refunds the swapper and matcher their original amounts. If an MEV bot does not pick up the execute, the UI exposes an Execute button for the user to call. Refunds happen when the execution price is outside the slippage tolerance passed by the swapper, when there is not enough liquidity at the final price, or when the implied blocks-per-second sanity check fails.

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 the pre-match window. If nobody matches before this timer ends, the swap can no longer be matched. 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. 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. In V2, the matcher posts this liquidity directly when matching the swap and also becomes the initial reporter. If you set 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 capital the matcher has to commit.