Open lukaspetrasek opened 3 months ago
Essentially we are asking for an "ordebook projection" of the CL AMM (MySwap).
Part of that is that on some specified price levels we want to know how much liquidity is between this price level and 5% below (or above).
Can I take up this issue?
can i work on this?
Hi, can you guys please tell me something about you, what skills/experience do you have and how do you plan to tackle this issue? This task is not simple, so I have to learn more information before I assign anyone 🙏🏼
𝑘 x⋅y=k, where 𝑥 x and 𝑦 y are the amounts of two tokens in the pool and 𝑘 k is a constant.
𝑘 x⋅y=k.
Step-by-Step Calculation: Current Pool Balance:
2 𝑥 y=2x Constant Product:
2 𝑥 2 k=x⋅2x=2x 2
Liquidity at Various Price Levels: To find the amount of USDC that can be swapped for STRK without pushing the price by more than 5%, we need to consider the price levels 1.9 1.9, 1.8 1.8, ..., 1 1 USDC per STRK.
For a new price 𝑝 ′ p ′ :
𝑦 ′ / 𝑥 ′ p ′ =y ′ /x ′
𝑝 ′ ⋅ 𝑥 ′ y ′ =p ′ ⋅x ′
We need to maintain the constant product:
𝑘 x ′ ⋅y ′ =k Let's compute this step-by-step for each new price level.
Example Calculations: Current Situation:
2 , 000 , 000 k=1000×2000=2,000,000. New Price Level: 1.9 USDC per STRK
1.9 ⋅ 𝑥 ′ y ′ =1.9⋅x ′
2 , 000 , 000 1.9 x ′2 = 1.9 2,000,000
2 , 000 , 000 1.9 x ′ = 1.9 2,000,000
1.9 × 1024.7 ≈ 1946.93 y ′ =1.9×1024.7≈1946.93 Available Liquidity at 1.9 USDC per STRK:
Initial USDC: 2000 2000 Remaining USDC: 1946.93 1946.93 Swappable USDC: 2000 − 1946.93 ≈ 53.07 2000−1946.93≈53.07 We can repeat this process for other price levels 1.8 1.8, 1.7 1.7, etc.
Let's calculate this iteratively for a series of price levels using Python.
Python Calculation: python Copy code import math
def available_liquidity(initial_x, initial_price, new_prices): initial_y = initial_price initial_x k = initial_x initial_y
liquidity_info = []
for p in new_prices:
x_prime = math.sqrt(k / p)
y_prime = p * x_prime
available_usdc = initial_y - y_prime
liquidity_info.append((p, available_usdc))
return liquidity_info
initial_x = 1000 # initial amount of STRK initial_price = 2 # current price of 1 STRK in USDC new_prices = [1.9, 1.8, 1.7, 1.6, 1.5, 1.4, 1.3, 1.2, 1.1, 1.0] # new price levels
liquidity = available_liquidity(initial_x, initial_price, new_prices) liquidity Let's run the Python code to get the exact values.
Here are the available amounts of USDC that can be swapped for STRK at various price levels without pushing the price by more than 5%:
1.9 USDC per STRK: 50.64 USDC 1.8 USDC per STRK: 102.63 USDC 1.7 USDC per STRK: 156.09 USDC 1.6 USDC per STRK: 211.15 USDC 1.5 USDC per STRK: 267.95 USDC 1.4 USDC per STRK: 326.68 USDC 1.3 USDC per STRK: 387.55 USDC 1.2 USDC per STRK: 450.81 USDC 1.1 USDC per STRK: 516.76 USDC 1.0 USDC per STRK: 585.79 USDC These amounts represent the liquidity available in the pool at each specified price level. As the price of STRK decreases, the amount of USDC that can be swapped for STRK increases.
Hi @Adesooye , can you pls write a more concise message? Also, mind that this task is to compute liquidity on the MySwap CLMM, not their V2 AMM.
@lukaspetrasek, I would like to work on this issue. I am a smart contract developer in Solidity and Cairo languages
Here's my approach; I will compute the available liquidity at MySwap CLMM for the STRK-USDC pair at various price levels without significantly affecting the price
The first thing is to obtain pool data, by getting the current state of the STRK-USDC liquidity pool from MySwap, including the total amounts of STRK and USDC.
Estimate the price impact of swapping USDC for STRK at different price levels. This involves determining how much USDC can be swapped without causing the price to change by more than 5%.
For each price level (e.g., 1.9 USDC, 1.8 USDC,..., 1 USDC), calculate the maximum amount of USDC that can be swapped without exceeding the 5% price impact threshold.
Ensure to document my findings for reference sake
Okay, assigning you @estherbreath 👍🏼
@estherbreath Let me know if everything is clear. If you have any questions, please ask here. What is you TG handler please? 🙏🏼
Consider joining our TG group. See also our contributor guidelines.
@lukaspetrasek My TG handle: @Bosslady248
Hi @estherbreath , any progress on this?
Almost done
Hi, what is the status of this task, I would like to take this one as far as I have already implemented Haiko and also AMM for uniswap V2 and have experience to manage this task. My approach is next:
Hi @estherbreath , unassigning you because you didn't submit any PR yet and putting @faurdent instead. Good luck @faurdent !
Compute available liquidity at MySwap CLMM for any given token at any given price level.
Let's choose, for example, the STRK-USDC pair and assume the current price is 2 USDC per 1 STRK. We're interested in the amounts of USDC that we'll be able to swap for STRK at MySwap while not pushing the price by more than 5% in a scenario where the STRK price falls to, e.g., 1.9 USDC, 1.8 USDC, ... 1 USDC, etc.