Swaps

The core functionality of Ambient is to allow users to exchange one type of token for another at fair market prices. If liquidity exists for a given pair in the DEX contract, then users will be able to swap between tokens. The frontend web app provides an interface for general-purpose swaps.

If adequate liquidity exists in a given for the pair, a swap will most likely be executed as a single hop. Single hops incur lower liquidity and gas fees, so are preferred. A multihop swap is when swaps across multiple pools are chained, usually in the case when there's little to no liquidity in any pair between the input and output token. The on-chain contracts take a pre-determined path. Finding a cost efficient price multihop path, or routing. Ambient provides an off-chain API for approximately optimal routing, but alternative clients are free to implement their own routing algorithms based on publicly available on-chain data.

The intermediate tokens in a multihop swap are those tokens in the middle of the path that are only temporarily held when swapping through a sequence of pairs. Unlike in other AMMs, intermediate tokens in Ambient are never transferred because settlement occurs based on the net debit agains the entire DEX protocol. This reduces both the amount of gas from unnecessary token transfers, as well as taxable/capital events on the intermediate tokens.

In addition to the input and output tokens, the user defines the following parameters on a per swap basis (with sensible defaults chosen by the front-end app):

  • Quantity to swap. This either be a fixed input quantity or fixed output quantity.

  • Slippage. The minimum possible output tokens or maximum possible input tokens the user is willing to accept. Past this point the swap transaction will revert.

  • Settlement. Swaps can either be settled directly with ERC20 tokens or to/from the user's surplus collateral balance at the DEX. A user can mix-and-match, i.e. pay input as ERC20 token transfer and receive output as surplus collateral.

Last updated