Koniverse / SubWallet-Extension

SubWallet is the comprehensive non-custodial wallet solution for Polkadot, Substrate & Ethereum ecosystems.
https://www.subwallet.app
Apache License 2.0
93 stars 65 forks source link

Research Uniswap price impact #3269

Closed nampc1 closed 2 months ago

nampc1 commented 2 months ago

We need to calculate price impact for swaps on Asset Hub to warn users

nampc1 commented 2 months ago

https://calculator.academy/price-impact-calculator/ https://stackoverflow.com/questions/74282316/uniswap-v2-pool-priceimpact https://support.uniswap.org/hc/en-us/articles/8643794102669-Price-Impact-vs-Price-Slippage https://dailydefi.org/articles/price-impact-and-how-to-calculate/ https://stackoverflow.com/questions/74282316/uniswap-v2-pool-priceimpact https://medium.com/@arian.web3developer/everything-about-price-impact-slippage-rate-and-deadline-in-dex-swaps-explained-on-uniswap-dex-7f700ffa3948 https://blog.uniswap.org/uniswap-v3-math-primer https://blog.uniswap.org/uniswap-v3-math-primer-2 https://medium.com/luchadores-chronicles/how-to-calculate-price-impact-b4c87d8b10ed

bluezdot commented 2 months ago

Short note: We apply Fomular 3. Base formulation:

Where:


=> Finally formula 1: PI = ym/k


=> Finally formula 2: PI = m/x


=> Finally formula 3: PI = (x + m)^2 / xy

Sokol142196 commented 2 months ago

Version test: https://9dcf8574.subwallet-webapp.pages.dev/ Validation passed in case:


Re-check:

Sokol142196 commented 2 months ago

Version test: https://00ebb04b.subwallet-webapp.pages.dev/

Validation passed in cases: