🌊Pools

Introduction

Lovely Swap liquidity pools serve as trading venues for pairs of ERC-20 tokens. When a pool contract is created, it starts with zero balances of each token. To initiate trading, someone must provide an initial deposit of both tokens. The first liquidity provider sets the initial price of the pool and is incentivized to deposit an equal value of both tokens. If the deposit ratio differs from the current market rate, it creates an arbitrage opportunity that external parties are likely to exploit.

Subsequent liquidity providers must add tokens in proportions that match the current pool price to avoid their liquidity being arbitraged. If they believe the current price is incorrect, they can arbitrage it to their preferred level before adding liquidity.

Pool Tokens

When liquidity is added to a pool, unique tokens called liquidity tokens are minted and sent to the provider's address. These tokens represent the provider's share of the pool. The number of liquidity tokens issued is proportional to the provider’s contribution. For new pools, this amount equals sqrt(x * y), where x and y are the amounts of each token provided.

A 0.3% fee is charged on every trade and is distributed pro-rata to all liquidity providers in the pool. To withdraw their liquidity and any accrued fees, providers must burn their liquidity tokens, which converts them back into their share of the pool along with their portion of the fees.

Liquidity tokens are tradable assets, allowing providers to sell, transfer, or otherwise utilize them as they wish.

Advanced Topics

Understanding Returns: Learn how liquidity providers earn returns through fees and price changes.

Fees: Understand the fee structure and its distribution among liquidity providers.

Why Pools? Lovely Swap distinguishes itself by using liquidity pools instead of order books to derive asset prices and match buyers and sellers.

Liquidity Pools vs. Order Books

Traditional order books involve placing discrete orders on a central ledger, requiring active management and sophisticated infrastructure, which limits participation to advanced traders. In contrast, Lovely Swap's liquidity pools leverage Ethereum's strengths: a trusted code execution environment, an autonomous and perpetually running virtual machine, and an open, permissionless access model that fosters a rapidly growing ecosystem of virtual assets.

A pool on Lovely Swap is simply a smart contract managed by user interactions. Swapping tokens involves calling the swap function on a pool contract while providing liquidity involves calling the deposit function.

Trading Fee and Fair Distribution

Lovely Swap charges a 0.15% DEX fee and a 0.15% fee for liquidity providers. This structure allows Lovely Swap to efficiently support both platform maintenance and incentivize liquidity provision.

The 0.15% DEX fee ensures a sustainable revenue stream for the platform, which can be utilized for future development, maintenance, and improvements. By maintaining a relatively small fee, Lovely Swap aims to minimize the impact on traders while still capturing sufficient value to support the protocol's growth and stability.

The liquidity provider fee of 0.15% is directly distributed to those who contribute liquidity to the pools, rewarding them for their participation and encouraging the continual addition of liquidity, which is crucial for maintaining healthy trading volumes and price stability on the platform.

Both fees are designed to be collected in a gas-efficient manner. Instead of imposing an additional overhead on each individual trade, Lovely Swap accumulates these fees and distributes them only during liquidity addition or removal events. This approach ensures that the fees are collected efficiently without placing unnecessary burdens on traders and liquidity providers.

Accumulated Fees as a Function of Liquidity Growth:

f1,2 =1  k1k2f_{1,2}\ =1\ -\ \frac{\sqrt{k_1}}{\sqrt{k_2}}

This formula calculates the accumulated fees between t1 and t2 as a fraction of the total liquidity in the pool at t2. It does this by looking at the geometric growth of the constant product k = x * y, where x and y are the token reserves.

The formula to calculate the new liquidity tokens (sm) to mint for the fee recipient is:

smsm +s1 =Φ  f1,2\frac{s_m}{s_m\ +s_1}\ =\Phi\ \cdot\ f_{1,2}

This states that the new liquidity tokens (sm) minted for the fee recipient should represent their fee fraction (φ) share of the accumulated fees f(t1, t2) between t1 and t2.

Rearranging, we get:

sm =k2k1(1Φ 1)  k2+k1  s1s_m\ =\frac{\sqrt{k_2}-\sqrt{k_1}}{\left(\frac{1}{\Phi}\ -1\right)\ \cdot\ \sqrt{k_2}+\sqrt{k_1}}\ \cdot\ s_1

Here, k1 and k2 are the values of k (constant product reserves) at times t1 and t2 respectively. s1 is the total supply of liquidity tokens at t1, and fee fraction (φ) is the protocol's share of fees (1/6 for 0.05% fee). Essentially, this formula computes the geometric revenue growth between t1 and t2, and mints the fee recipient's share of that growth as new liquidity tokens.

Setting φ to 1/6 results in the formula:

sm =k2 k15  k2 + k1  s1s_m\ =\frac{\sqrt{k_2}-\ \sqrt{k_1}}{5\ \cdot\ \sqrt{k_2}\ +\ \sqrt{k_1}}\ \cdot\ s_1

For example, if the initial deposits were 100 DAI and 1 ETH, then later the reserves were 96 DAI and 1.5 ETH, with an initial total liquidity of 10 tokens, the fee recipient would mint:

sm =1.5  96  1  1005  1.5  96 + 1  100  10 0.0286s_m\ =\frac{\sqrt{1.5\ \cdot\ 96}\ -\ \sqrt{1\ \cdot\ 100}}{5\ \cdot\ \sqrt{1.5\ \cdot\ 96}\ +\ \sqrt{1\ \cdot\ 100}}\ \cdot\ 10\ \approx0.0286

This innovative fee distribution mechanism avoids the gas costs of charging fees on each trade while ensuring fair payment to the protocol.

Last updated