πSwaps
Token swaps in SwapBased are a simple way to trade one ERC-20 token for another.
For end-users, swapping is intuitive: a user picks an input token and an output token. They specify an input amount, and the protocol calculates how much of the output token theyβll receive. They then execute the swap with one click, receiving the output token in their wallet immediately.
weβll look at what happens during a swap at the protocol level in order to gain a deeper understanding of how SwapBased works.
Swaps in SwapBased are different from trades on traditional platforms. SwapBased does not use an order book to represent liquidity or determine prices. SwapBased uses an automated market maker mechanism to provide instant feedback on rates and slippage.
The automated market making algorithm used by SwapBased revolves around the constant product formula x*y=k, where k is the invariant.
Each pair on SwapBased is actually underpinned by a liquidity pool. Liquidity pools are smart contracts that hold balances of two unique tokens and enforces rules around depositing and withdrawing them.
When either token is withdrawn (purchased), a proportional amount of the other must be deposited (sold), in order to maintain the constant.
Liquidity provider fees
There is a 0.3% fee for swapping tokens. This fee is split by liquidity providers proportional to their contribution to liquidity reserves.
Swapping fees are immediately deposited into liquidity reserves. This increases the value of liquidity tokens, functioning as a payout to all liquidity providers proportional to their share of the pool. Fees are collected by burning liquidity tokens to remove a proportional share of the underlying reserves.
Since fees are added to liquidity pools, the invariant increases at the end of every trade. Within a single transaction, the invariant represents token0_pool / token1_pool
at the end of the previous transaction.
Last updated