diff --git a/uniswap/uniswap-v2.md b/uniswap/uniswap-v2.md index 74bf637..737b3ad 100644 --- a/uniswap/uniswap-v2.md +++ b/uniswap/uniswap-v2.md @@ -2,11 +2,13 @@
+### tl; dr + * each Uniswap liquidity pool is a trading venue for a pair of ERC20 tokens
-Screen Shot 2022-10-10 at 1 45 22 PM +Screen Shot 2022-10-10 at 1 45 22 PM * whenever liquidity is deposited into a pool, unique tokens known as liquidity tokens are minted and sent to the provider's address @@ -15,6 +17,37 @@
+---- + +### arbitrage opportunities + +#### 💡 check my [amm arbitrage toolkit](https://github.com/MEV-WAIFU-LABS/amm_arbitrage_toolkit) for a clean nice code on uniswap v2 protocol + +* let's chat about a bot looking for uniswap-like arbitrages which it could perform after the opportunity tx take advantages of liquidity disparities accross pools +* a pool with X WETH and Y USDC allows users to swap WETH and USDC, the governing principle of the pool is that the product of X * Y is always constant (the uniswap invariant) +* for a pool with reserves of (X, Y) we can work out how much USDC out we expect for selling delta X WETH +* the pool also takes a fee of ~30bps (~0.3%) + +
Screen Shot 2022-10-16 at 12 29 14 PM +Screen Shot 2022-10-16 at 12 29 22 PM +Screen Shot 2022-10-16 at 12 29 43 PM +Screen Shot 2022-10-16 at 12 29 50 PM + +
+ +##### bots step + +1. once we figured out how to perform swaps to max profit, the bot needs to acquire delta X of the initial token to perform these swaps (e.g. using a flash loan from aave) +2. then the bot needs to bundler the flash loan plus both swaps and transfer of flash loan back to aave into a single tx (this can be done using a custom smart contract that is pre-deployed on chain) +3. once the tx is created and signed, it's submitted to the mempool to be mined. there are many other bots searching for the same opportunities +4. we want to ensure that our tx gets mined first, this means our arb tx should follow the original tx in the same block and be mined immediatially aftward. this is what's known as "back run". +5. in order to achieve a back run, the bot needs to first understand the gas price that the original tx offered, and then needs to copy these exact parameters in the arb tx +6. finally, the tx is signed and submitted to the mempool directly by the bot for validation and free money + + +
+ +---- ### lp burn