Skip to content
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

feat(slippage): small order slippage v2 #4934

Open
wants to merge 11 commits into
base: develop
Choose a base branch
from

Conversation

alfetopito
Copy link
Collaborator

@alfetopito alfetopito commented Oct 1, 2024

Update 2024/10/03

Added feature flag smartSlippageFeeMultiplierPercentage, that returns the multiplier value and can still be used to feature flag the individual feature of small orders slippage.

Also, slippage is now capped at 50%.

New testing steps

  1. Enable smartSlippageFeeMultiplierPercentage and disable isSmartSlippageEnabled
  2. Pick sell/buy/amounts and observe the suggested slippage
  • Should still work independent from BFF's slippage
  1. Pick a tiny sell amount and observe the UI and the console logs
  • Max suggested UI value should be 50%
  • Console logs should show more than 5000
    image

One more fun test is to add/pick new values to be served when on for the new feature flag:
image
And then observe the slippage change accordingly in the UI.

Summary

Supersedes #4911

Instead of using the fee % in relation to order size, calculate how much slippage is needed if the fee is 50% higher.
This value is added to the one returned by BFF.

⚠️ Tooltips still not updated

To Test

  1. Make sure the Launch darkly flag is on
  2. This will depend on current network conditions, so play around with input amounts to get it within those ranges
  3. Place the order
  • Should trade somewhat fast, hopefully. Not guaranteed, though.

You can also observe all the smart slippage values by filtering the console logs by SmartSlippage

Copy link

vercel bot commented Oct 1, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated (UTC)
cosmos ✅ Ready (Inspect) Visit Preview Oct 3, 2024 6:00pm
cowfi ✅ Ready (Inspect) Visit Preview Oct 3, 2024 6:00pm
explorer-dev ✅ Ready (Inspect) Visit Preview Oct 3, 2024 6:00pm
swap-dev ✅ Ready (Inspect) Visit Preview Oct 3, 2024 6:00pm
widget-configurator ✅ Ready (Inspect) Visit Preview Oct 3, 2024 6:00pm

* for the limit price to take this much more fee.
* More relevant for small orders in relation to fee amount, negligent for larger orders.
*/
function useSmartSlippageFromFeePercentageV2(): number {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The hooks deserves its own file :)
I would also suggest to extract the whole logic into a pure function and cover it by unit-tests

@elena-zh
Copy link

elena-zh commented Oct 2, 2024

Hey @alfetopito , I have some questions to clarify/suggestions:

  1. Why is the bff slippage added to the newly calculated one?
    image

  2. Why the slippage amount to add is so huge? Is this calculated on top of the granular slippage of 20%? Buy order:
    image
    Sell order:
    image

  3. When I keep 'Confirm' modal opened, I can see that slippage amount is constantly changing there. IMO, it is not good thing as it leads to the trade outcome change. So I'd whether show 'Price updated' warning on the modal OR freeze the slippage value on the modal until the order placement
    image

  4. When a price is loaded, I can see several slippage requests on console. Is this OK?
    3 slipp

  5. As we discussed in the meeting, we have 50% slippage limitation in the settings, so it would be nice to have it as a max when calculating a custom one
    image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants