How Tealswap works?
Tealswap is a decentralized exchange with automated market maker on Oasys hub-layer.
Last updated
Tealswap is a decentralized exchange with automated market maker on Oasys hub-layer.
Last updated
There are two types of participants in Tealswap, Traders and Liquidity Providers.
A trader is a user who swaps two listed ERC20 tokens(sells a ERC20 token and buys another ERC20 token). Amount of input and output of tokens is determined by constant product formula(see Constant Product Formula). A trader pays swap fees.
A liquidity provider is a user who deposits an equivalent value of two ERC20 tokens into the liquidity pool. Liquidity providers take a risk of impermanent loss(see Impermanent Loss) and are compensated with swap fees.
AMM is a trading mechanism that improved shortcomings of order book method. Instead of order books of buyers and sellers, market is automated with the provided liquidity. It overcomes an economic problem known as the coincidence of wants and enables an exchange to occur immediately. Ratio of swapped tokens is determined in AMM with constant product formula, a.k.a x*y = k. See below for the detailed explanations.
In the example above, we can see that the trader’s expected price of ETH to USD is 9.95 USD where the initial market price was 10 USD before the swap. This difference between current market price and the expected price is called price impact. In Tealswap, price impact is affected by relative size of an order to the liquidity pool. The larger the order to the pool, the further above the market price will the trade price be.
While lquidity providers expect pool’s growth as a reward, they take a risk of impermanent loss. Impermanent loss is unrealized loss that is calculated as a difference between value of LP tokens (if redeemed) and value of otherwise, not depositing into a pool and holding.
Graph below shows how much of impermanent loss liquidity providers are exposed to as price of two tokens change.
When ETH value decreases (ETH reserve increased and USD reserve decreased), constant product formula changes as below:
Term | Description |
---|---|
Constant Product Formula is a method to determine the price of tokens when swap is executed. It refers to the equation below: , where and are reserve balance of two tokens in the pool and is a constant (whose value does not change with exchange of tokens). When swap occurs the reserve balance changes: , where is amount of outflowing token (token purchased) and is amount of inflowing token (token sold).
For example, let’s take a look at a case of ETH to USD swap. Let’s assume 1 ETH = 10 USD in market and there are 1,000 ETH and accordingly 10,000 USD token in liquidity pool. Selling 5 ETH, a trader inputs 5 ETH to the liquidity reserve. Then, to satisfy the constant product formula , the reserve outputs of USD token.
For example, let’s take a look again at a case of ETH to USD swap. Now there are 100,000 ETH and accordingly 1,000,000 USD token in liquidity pool. Selling 5 ETH, to satisfy the constant product formula , the reserve outputs of USD token. This time, expected price of ETH to USD is 9.999 USD.
When liquidity is provided to a pool, constant value increases accordingly (and vice versa). If (ratio of provided/previous liquidity) is provided, the equation is as below: , where and accordingly
Similarly after swap is executed with swap fees, swap fee is reserved to the pool which increases the value of . Redeeming LP token (removing liquidity), they are given ERC20 tokens amount in the same way. Liquidity providers expect swap fees accumulated during their provision period in return for their liquidity.
Assuming ETH price decreased to 5 USD, the formula becomes and market price becomes . This gives us which means there are 7,070 USD and 1,415 ETH in pool reserve. We can calculate impermanent loss here by comparing scenario of holding and providing liquidity.
ETH | USD | SUM | |
---|---|---|---|
ERC20
ERC20 tokens are fungibile tokens. Currently in Tealswap, stablecoins, USDC and USDT, and OAS(Oasys token) are supported.
Pool
A pair of two tokens makes a pool. When liquidity is added or removed, tokens in a pool are increased or decreased.
Holding(Initial)
1,000
10,000
15,000
LP token
1,415
7,070
14,145