In the world of DeFi, efficiency and flexibility are key to staying ahead of the curve. Orca has always been at the forefront of innovation, and with the introduction of SparseSwap, Orca is taking another significant leap forward.
SparseSwap addresses critical issues related to TickArray management in trading, offering a seamless experience that enhances liquidity utilization and reduces the friction previously encountered in trading.
What is SparseSwap?
SparseSwap is a comprehensive update designed to address specific challenges associated with TickArray accounts in trading on Orca. It introduces three core features:
- Trade crossing uninitialized TickArray Accounts
- On-chain TickArray account order adjustment
- V2 Swap accepts supplemental TickArrays
Let’s delve into each of these features and explore how they enhance the trading experience.
Trade crossing uninitialized TickArray accounts
Pain Point
Previously, when executing trades, the pool’s current price (sqrt_price
and tick_current_index
) could only move within the range of initialized TickArray accounts. This meant that even if liquidity was available in the range of uninitialized TickArrays, it couldn't be accessed, effectively halting trades prematurely.
Solution
SparseSwap revolutionizes this process by allowing the current price to move across several uninitialized TickArray accounts. Now, as long as liquidity exists, trades can proceed without interruption, even if the TickArray hasn’t been initialized.
In technical terms, SparseSwap treats uninitialized TickArrays as if they are initialized but with zero liquidity, allowing trades to cross these ranges without any issues. This method does not impact the calculation of fees and rewards, ensuring that all stakeholders are treated fairly.
On-chain TickArray account order adjustment
Pain Point
Previously, the swap instruction required that tick_array_0
always contain the pool's current price. This posed challenges when the price was near the edge of a TickArray, potentially leading to errors during execution.
For example, if a TickArray with a start of -88
was passed as tick_array_0
based on tick_current_index
during quote calculation, but the correct tick_array_0
at execution time should have had a start of 0
, the trade would fail.
In another example, a TickArray with start of 0
is passed as tick_array_0 based on tick_current_index (1) at the time of quote calculation. However, the correct tick_array_0 is a TickArray with start=-88 due to tick_current_index moving to -2 at the execution time, resulting in an error.
Solution
With SparseSwap, the Whirlpool program now automatically adjusts the order of the received TickArray accounts. This means that the order in which TickArrays are passed is no longer critical. The program dynamically adjusts to ensure that the correct TickArray is used based on the pool’s current price.
For instance, if the pool price has moved forward and resides on tick_array_1
, the program will act as if it received tick_array_1
as tick_array_0
. This adjustment ensures smooth execution without errors, even if the price moves within or outside the expected range.
This enhancement also allows for the inclusion of a fallback TickArray in tick_array_2
, further improving trade reliability.
V2 Swap Accepts Supplemental TickArrays
*This section is for V2(swap_v2 and two_hop_swap_v2) only. V1 (swap and two_hop_swap) does NOT support this feature.
Pain Point
While the ability to pass a fallback TickArray improves reliability, it also reduces the number of TickArray accounts available for trading, effectively limiting the trade to two TickArrays if a fallback is used.
Solution
SparseSwap V2 (swap_v2
and two_hop_swap_v2
) introduces the use of remaining_accounts
, allowing for the passing of up to three supplemental TickArray accounts. This ensures that even with a fallback account, traders can still utilize up to three TickArray accounts, maximizing liquidity and improving trade outcomes.
A maximum of six TickArray accounts can be passed, with the program selecting the most appropriate three for the trade. This added flexibility in V2 ensures that trades are not only more robust but also capable of leveraging the full range of available liquidity.
What Actions Are Required?
SparseSwap introduces several powerful features, but depending on your current setup, the actions required may vary:
SDK Update
The SparseSwap update is accompanied by a new version of the SDK (v0.13.4), which includes the necessary changes to handle these features. No breaking changes are introduced, although if you’re using a version older than 0.13.0, you’ll need to account for small breaking changes related to TokenExtensions.
How to Use the New Features
The following SDK functions have been updated to seamlessly integrate SparseSwap:
swapQuoteByInputToken
swapQuoteByOutputToken
swapQuoteWithParams
These functions now support optional parameters for fallback TickArrays, allowing you to specify whether to use fallback TickArrays based on your trading strategy.
Ending Notes
SparseSwap represents a significant advancement in how TickArray accounts are managed in trading on Orca. By addressing key pain points and introducing enhanced flexibility and robustness, SparseSwap ensures that traders can fully leverage available liquidity without encountering unnecessary interruptions or errors. We encourage all users to update their strategies and SDKs to take full advantage of these new features.
For any questions or further clarification, join the discussion on our Public Discord channel.
Thank you for being part of the Orca community! 🐳
— — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — —
Website | Docs | Twitter | Discord
Disclaimer: The content of this communication is not financial advice and should not be relied on by any persons as financial advice. This communication has not been provided in consideration of any recipient’s financial needs. We have not conducted any financial assessment based on the personal circumstances of any recipients. Before using the protocol, carefully review all relevant documentation and consider risks including total loss of funds.