-
Notifications
You must be signed in to change notification settings - Fork 150
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SparseSwap (SDK) #162
SparseSwap (SDK) #162
Conversation
@@ -170,7 +302,7 @@ describe("swap arrays test", () => { | |||
adjustForSlippage(quote.estimatedAmountOut, slippageTolerance, false).toString() | |||
); | |||
assert.equal(quote.estimatedAmountIn.toString(), tradeAmount); | |||
assert.doesNotThrow(async () => await (await whirlpool.swap(quote)).buildAndExecute()); | |||
await assert.doesNotReject(async () => await (await whirlpool.swap(quote)).buildAndExecute()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for async fn, we should use doesNotReject
.
sdk/src/utils/public/swap-utils.ts
Outdated
* @param tickArrays - Fetched tickArrays to interpolate. | ||
* @returns An array of TickArray objects with zeroed tick data if they are not initialized. | ||
*/ | ||
public static interporateUninitializedTickArrays( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: interpolate
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh...🤦
Good catch! 🙏
* draft for swap ix * use vec * add SparseSwapTickSequenceBuilder * use ref * v2 support, add errors * refactor: use named field * update two_hop_swap v1/v2 to support ss * add cargo test test cases * add integration test (partial) * add ProxiedTickArray to reduce heap usage program can use up to 32KB heap * fix testcases * refactor s/additional/supplemental * add twoHopSwap test b to a * add twoHopSwap test a to b * update client-side remaining accounts handling * add supplemental tick arrays test cases * add supplemental tick array test cases (2) * fix existing test cases * address review comment (add comments, small refactor) * address review comments (refactor with TickArrayType trait) * fix testcases on swap * adjust error code (merge introduce 1 new error code) * SparseSwap (SDK) (#162) * intro the benefit of SparseSwap into SDK * avoid breaking parameter change * fix failed test cases * adjust fallback tickarray handling * fix typo * add new test cases * add test cases for fallback * address review comment (fix typo)
This PR introduces the benefits provided by SparseSwap into SDK.
We no longer need to stop quote right before uninitialized tickarray
The swapQuoteX function gets the estimate without any concern for the existence of uninitialized TickArrays.
Whirlpool.swap and the swapAsync behind it no longer pre-verify whether a TickArray is initialized or not.
To enjoy the benefit of not having to worry about uninitialized TickArrays by default, the SDK interpolate uninitialized TickArrays with zeroed data in swapQuoteWithParams function.
As a result, functions that use swapQuoteWithParams, such as sqapQuoteByInputToken, also benefit.
swapQuoteByInputToken
-->swapQuoteWithParams
swapQuoteByOutputToken
-->swapQuoteWithParams
swapQuoteWithParams
(direct use)User can insert fallback tickarray if they want
On the other hand, the behavior of supplemental tick arrays and preliminary additions to previous tick arrays are disabled by default. (
UseFallbackTickArray.Never
)This is to prevent breaking changes on the function interface.
If users want to add a fallback, they must explicitly use
UseFallbackTickArray.Always
orUseFallbackTickArray.Situational
.UseFallbackTickArray.Situational
Add a TickArray in the opposite direction as a fallback only if the price is at the end 1/4 of the current TickArray.
1/4 is fixed value. Devs who want to tune the behavior shoud use
swapQuoteWithparams
andSwapUtils.getFallbackTickArrayPublicKey
directly.How to add fallback tick array
If only one or two tickarrays are used in a trade (ta1=ta2), add it as ta2. (it is safe way because ta2 is dup of ta1)
This way is prefer because V1 users can also benefit.
On the other hand, if three TickArrays are used, it is added to the estimate as
supplementalTickArrays
and used only in the V2 instruction.Whirlpool.swap
uses V2 if the pool uses TokenExtension or ifsupplementalTickArrays
is not empty.