Swaps

Token swaps in Savmswap offer a straightforward method for exchanging one ERC-20 token for another.

For end-users, the process of swapping is user-friendly: a user selects an input token and an output token, specifies the amount they want to input, and the protocol calculates the corresponding amount of the output token they will receive. The swap is executed with a single click, resulting in the immediate receipt of the output token in their wallet.

This guide delves into what transpires during a swap at the protocol level, offering an enhanced understanding of how Savmswap operates.

Swaps in Savmswap differ from trading on traditional platforms. Unlike conventional systems that utilize an order book to represent liquidity or set prices, Savmswap employs an automated market maker mechanism to provide instantaneous feedback on rates and slippage.

As discussed in the Protocol Overview, each pair in Savmswap is underpinned by a liquidity pool. These pools are smart contracts that maintain balances of two distinct tokens and enforce rules around depositing and withdrawing these tokens.

The guiding principle here is the constant product formula. When one token is withdrawn (purchased), a proportional amount of the other token must be deposited (sold) to preserve the constant.

Anatomy of a Swap At its core, all swaps in Savmswap happen within a single function, appropriately named swap:

function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data);

Last updated