3. Token Exchange Formulas
Token exchanges within a Liquidity Bootstrapping Pool (LBP) involve two primary operations: "Swap Given In" and "Swap Given Out." These operations determine the amount of one token received when another is provided or the amount needed to receive a specified amount of another token
These operations are distinct from simple Buy/Sell transactions, as each swap involves both acquiring one token and relinquishing another. Since swaps are bi-directional, Tokenxβ and Tokenyβ can represent either TokenTradedβ or TokenAnchorβ, depending on the direction of the swap.
3.1. Operation : βSwap Given Inβ
The βSwap Given Inβ operation refers to the process of determining how much of a token you will receive when you input a specific amount of another token into a liquidity pool. This is typically used when a participant knows the amount they want to trade and wants to calculate how much they will receive in return.
The process begins by inputting the desired amount of tokens into the pool. The amount of tokens received is calculated based on the current token volumes and weights within the pool, using the formulas below. This calculation considers the changing dynamics within the pool, ensuring that the received amount reflects the most current state of the liquidity pool.
Because weights adjust the price sensitivity in an LBP, the βSwap Given Inβ operation introduces a non-linear relationship to the original swap formula (without weights) from general liquidity pools; this effect is expressed by raising the volume ratio to the power of the weight ratio, WeightxβWeightyββββ, resulting in a power-law behavior.

TokenxReceivedβ=VolumexβΓ[1β(Volumeyβ+TokenyInputβVolumeyββ)]WeightxβWeightyββ
Where
TokenxReceivedβ : Amount of Tokenxβ being received from the pool (swapped out).
TokenyInputβ : Amount of Tokenyβ being input into the pool (swapped in).
Volumexββ : Current volume of Tokenxβ in the pool before the transaction.
Volumeyββ : Current volume of Tokenyβ in the pool before the transaction.
Weightxββ : Current weight of Tokenxβ in the pool.
Weightyββ : Current weight of Tokenyβ in the pool.
The above formulas assume that the ratio between the input token volume (TokenyInputβ) and the pool's existing volume of the token (Volumeyβ) remains small. As the input token volume TokenyInputβ approaches the total volume of the corresponding token in the pool (Volumeyβ), the output received (TokenxReceivedβ) diminishes and may approach zero. This occurs because the increase in input drastically alters the pool's balance, leading to a situation where the received token amount becomes negligible. Extreme values for TokenyInputβ can cause the formula to produce outputs that are practically meaningless or extremely small, indicating that the pool is being heavily impacted by the trade.
3.2. Operation : βSwap Given Outβ
The "βSwap Given Outβ operation involves determining how much of a token needs to be input into the pool to receive a specific amount of another token. This is used when a participant knows the exact amount of the token they want to obtain and needs to calculate the corresponding input required.
To perform a βSwap Given Out,β the trader specifies the amount of the token they want to receive. The system then calculates the necessary amount of the other token that must be input into the pool based on the current volumes and weights of the tokens. This ensures the trader knows exactly how much of their existing tokens they need to commit to achieve their desired outcome.

TokenyInputβ=VolumeyβΓ[(VolumexββTokenxDesiredβVolumexββ)WeightyβWeightxβββ1]
Where
TokenxDesiredβ : Amount of Tokenxβ being received from the pool (swapped out).
TokenyInputβ : Amount of Tokenyβ being input into the pool (swapped in).
Volumexββ : Current volume of Tokenxβ in the pool before the transaction.
Volumeyββ : Current volume of Tokenyβ in the pool before the transaction.
Weightxββ : The current weight of Tokenxβ in the pool.
Weightyββ : The current weight of Tokenyβ in the pool.
The above formula assumes that the difference between Volumexβ and TokenxDesiredβ remains positive and non-zero. As TokenxDesiredβ approaches Volumexβ, the denominator in the formula approaches zero, causing the calculated TokenyInputβ to become undefined or extremely large. This scenario represents a situation where the pool is nearly depleted of Tokenxβ, making it impractical or impossible to perform the swap.
Last updated