Liquidity using guide
Introduction
LP (Liquidity Provider) refers to token holders who combine two different tokens (such as RGas
and GROW
) into a token pair and stake it in Rooch’s liquidity pool (Farm). These pools receive liquidity from RGas
and GROW
, and liquidity providers are rewarded based on their contribution to the pool (in the form of $LPXP
). Users holding $LPXP
will have the opportunity to receive $ROOCH
airdrops in the future.
Rooch now launches staking for RGas
and GROW
token pairs, and follows up with a simple demo to show the staking process.
- Website link: https://portal.rooch.network/trade/liquidity (opens in a new tab)
- Portal FAQ: https://rooch.network/learn/miscellaneous/portal#faq (opens in a new tab)
Staking process
Enter the Portal page, select Liquidity
and click on the Add
button on the right:
Just fill in the RGas
and the LP pair will automatically calculate the GROW
dosage:
The amount is calculated based on the official Swap pool, and the calculation formula is:
amount-in: The number of tokens
reserve-in: The token reserve
reserve-out: Output token reserve
fee-rate: Processing rate
amount-in-with-fee = amount-in * fee-rate
amount-out = (amount-in-with-fee * reserve-out) / (reserve-in * 10000 + amount-in-with-fee)
amount-in = (reserve-in * amount-out * 10000) / (reserve-out - amount-out * fee-rate) + 1
For detailed explanation, please refer to the code comments:
// Calculate how many output tokens a user can obtain
public fun get_amount_out(
amount_in: u64,
reserve_in: u64,
reserve_out: u64,
fee_rate: u64,
): u64 {
assert!(amount_in > 0, ErrorInputTokenAmount); // Make sure the input amount is greater than 0
assert!(reserve_in > 0 && reserve_out > 0, ErrorInsufficientLiquidity); // Ensure that the pool is fluid enough
let amount_in_with_fee = (amount_in as u128) * (fee_rate as u128); // Calculate the gas fee
// Based on the constant product formula: (x + Δx)(y - Δy) = xy Calculate the output amount
let numerator = amount_in_with_fee * (reserve_out as u128);
let denominator = (reserve_in as u128) * 10000u128 + amount_in_with_fee;
((numerator / denominator) as u64)
}
// Calculate how many input tokens are required to obtain a specific number of output tokens
public fun get_amount_in(
amount_out: u64,
reserve_in: u64,
reserve_out: u64,
fee_rate: u64
): u64 {
assert!(amount_out > 0, ErrorOutputTokenAmount);
assert!(reserve_in > 0 && reserve_out > 0, ErrorInsufficientLiquidity);
// Calculate in reverse from the constant product formula, add 1 to ensure that there is enough input
let numerator = (reserve_in as u128) * (amount_out as u128) * 10000u128;
let denominator = ((reserve_out as u128) - (amount_out as u128)) * (fee_rate as u128);
(((numerator / denominator) as u64) + 1u64)
}
Check the estimated income of the LP group, click the Confirm
button to complete the LP staking:
You can see the LP situation of the group just now:
Click the Remove
button on the right to unstaking:
The calculation formula for group LP pairs:
point = x / x pool * 100%
y = y pool * point
Earn token pairs
After forming an LP, you can stake the LP to Farm to obtain the income of the token pair. If you simply form a token pair, there will be no income.
Click the Stake LP
button to stake token pairs:
After staking an LP, you can obtain $LPXP
income.
In the Rooch Network Tokenomics (opens in a new tab) article released by Rooch, 5%
of the $ROOCH
tokens will be used to incentivize LP providers, and holding $LPXP
can earn $ROOCH
airdrops in the future.