Auto Slippage #16

Open
opened 2025-11-18 00:24:41 +00:00 by tim · 0 comments
Owner

If the user sets slippage to "Auto", we can query swapAmounts() without a limit price to see what the unlimited slippage would be for the current input size. We can then increase that number with a little buffer, alert the user if the slippage is very high (above 1-2%), and cap the slippage at no more than 2% in all cases, even under Auto.

For the buffer we need to add to the reported current slippage, let's add 20% to the reported slippage, and make the minimum Auto slippage be not less than the swap fee. For example, if the swap fee is 0.20% we would also have a minimum Auto slippage of 0.2%

function autoSlippage() {
  {swapInputAmount, swapOutputAmount}= pool.swapAmounts(...) // NO LIMIT in this swapAmounts
  price = PoolInfo.price(pool,...)
  slipPrice = swapOutputAmount / swapInputAmount
  slippage = 1 - slipPrice / price
  slippage *= 1.2
  slippage = Math.max(slippage, swapFee)
  slippage = Math.min(slippage, 0.02)
}
If the user sets slippage to "Auto", we can query swapAmounts() without a limit price to see what the unlimited slippage would be for the current input size. We can then increase that number with a little buffer, alert the user if the slippage is very high (above 1-2%), and cap the slippage at no more than 2% in all cases, even under Auto. For the buffer we need to add to the reported current slippage, let's add 20% to the reported slippage, and make the minimum Auto slippage be not less than the swap fee. For example, if the swap fee is 0.20% we would also have a minimum Auto slippage of 0.2% ```javascript function autoSlippage() { {swapInputAmount, swapOutputAmount}= pool.swapAmounts(...) // NO LIMIT in this swapAmounts price = PoolInfo.price(pool,...) slipPrice = swapOutputAmount / swapInputAmount slippage = 1 - slipPrice / price slippage *= 1.2 slippage = Math.max(slippage, swapFee) slippage = Math.min(slippage, 0.02) } ```
tim added the
low-pri
label 2025-11-24 15:11:19 +00:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: Liquidity.Party/web#16
No description provided.