🧬
Head First DeFi: TX & Strategies
  • Decoding the DNA of DeFi Transactions & Strategies
    • From Arbitrage, Sandwich to JIT and Oracle Manipulation
    • Be Prepared To Explore the DeFi World
    • Case Study Format
  • MEV Transaction & Strategy 101
    • A $3.2 Million Profit Arbitrage, the Most Lucrative MEV of 2022
    • Understand Back-Run Arbitrages and Their Signals and Join the MEV Game.
    • Wallchain's MEV Arbitrage Redistribution
    • MEV Blocker, the multi-transaction MEV redistribution system that refunds 90% of builder rewards
    • With NFT arbitrage, someone was snipping your Baby Doge.
    • The Hidden Tax That You Should Know About
    • MEV-Share, Flashbots' MEV Redistribution Solution
  • Don't Let Your Trading Become the Recipe of Someone's Sandwich
    • The Notorious Jaredfromsubway.eth's Sandwich Attack
    • Combined with Flash Loan, This Leveraged Sandwich Launched the Attack with Millions of Volumes
    • Sandwich Targeting Liquidity Providers
    • The Flash-Loan-Enabled Sandwich Attack against Ethereum Foundation
  • Under the Hood of the DeFi Lego
    • What's Really Going on When Processing Liquidity in a Uniswap Pool?
      • Pretend You Are One of the Shareholders of a Bank Branch.
      • Let's Match the Bank Branch to a Uniswap Pool.
      • Adding Liquidity.
      • Removing Liquidity.
      • Conclusion
    • Liquidation: A Good Entry Point to Comprehend Internal Accounting Used by Many DeFi Protocols.
    • A Cross-Chain Arbitrage: The Art of Arbitraging BANANA Cross BSC and Polygon Chains
    • Liquidity Rebalancing: Moving Around $9.4 Million for More Fee Revenues.
    • Rebalancing loan positions utilizing AAVE Flash loan
    • How Does the Grok Token Exploiter Exploit the X Token By Baking His Own Cake And Eating it?
  • Unlocking the Power of Advanced DeFi Transactions and Becoming a DeFi Sleuth
    • Just-in-Time, an MEV Type That Benefits Traders in the Same Trading Venue
    • A Bot Devised Arbitrage Strategies Centered on Autonomous Minting and Burning of Synthetic Tokens
    • The Defect in a Lending Protocol's Oracle Module Was Exploited by a Bot to Generate a $110K Profit
    • A $296K-Profit Arbitrage Done by the Lightning Reflex Bot After the Vyper-Curve Exploit
    • Coffeebabe.eth Utilized Curve's CRV/WETH Pool's Price Deviation for a $5.4 Million Profit Arbitrage.
    • An Attacker Baited MEV Arbitrage Bots and Emptied Their Wallets
    • How Enso Solves 73.5ETH in 116 Steps in One Transaction
Powered by GitBook
On this page

Was this helpful?

  1. Under the Hood of the DeFi Lego
  2. What's Really Going on When Processing Liquidity in a Uniswap Pool?

Removing Liquidity.

PreviousAdding Liquidity.NextConclusion

Last updated 1 year ago

Was this helpful?

When removing liquidity from a pool, several things will happen . Remember, you are still the liquidity provider here. Let's use the above tables again for easier understanding.

  • MOVE 1: Your exclusive shares of the pool in "virtualLiquidity-350101" will be burned to reflect your liquidity removal. This is a virtual shares "burn" operation added by EigenTx to indicate the internal accounting operation. Remember that we've added "minted," 2 virtual shares in the Adding Liquidity transaction.

  • MOVE 2: The total shares of the pool will remove your shares from the total share "virtualLiquidity." This is also a virtual shares "burn" operation added by EigenTx to indicate the internal accounting operation.

  • MOVE 3: The internal assets position data will remove your assets. Since we did not mint any virtual assets in the Adding Liquidity transaction, here we need to "mint" the virtual assets first. These are also "virtual" operations.

The internal accounting processes of Uniswap and Bank are generally similar, with the difference being that, on Uniswap, after a user deposits money, their assets are mixed with others and follow the changes in currency holdings according to the AMM curve. Therefore, when depositing money, it is not necessary to record how much of each token has been deposited. When the liquidity is removed, Uniswap calculates the specific amount of tokens that can be taken out based on the provider's liquidity shares.

  • MOVE 4: The removed virtual assets from the pool's internal assets positions will be added to your external position data, which are "mint" operations. These are also "virtual" operations.

  • MOVE 5: Now, the pool's internal accounting operations have done the removal process. Then, the pool transfers the actual assets to you, including the liquidity fees you earn.

  • MOVE 6: To keep the sheet balance, the internal and external position data need to "burn" the virtual assets. These are also "virtual" related operations.

  • MOVE 7: In the end, the Position NFT will be burned to reflect the liquidity removal.

Here is the whole token flow chart.

It is time to thoroughly break down the steps involved and match the abovementioned moves.

Steps 0-1: The two virtual internal assets positions minted virtualOwed0WBTC and virtualOwed1USDC and sent to the actual total internal position contract. MOVE 3. These 2 steps are overlapped in the chart. But you can find the details in the transfer list shown below.

Go to the next step.

Step 2: The virtual total shares burned your shares. MOVE 2.

Step 3: Your exclusive external virtual shares were burned. MOVE 1.

Steps 4-5: The two virtual external assets positions minted virtualOwed0WBTC-350101 and virtualOwed1USDC-350101 and sent to the actual total internal position contract. MOVE 4.

Steps 6-7: The pool transferred your liquidity and fees you earned back to you. MOVE 5.

Steps 8-11: Now that both the internal and external representation of the liquidity provider account should have no balance. UNI-V3-POS and UNI-V3-POS-350101 burned the corresponding balances of virtual assets. MOVE 6.

Step 12: This matches the MOVE 7 that burned the position NFT to reflect the liquidity removal.

Step 13: The builder was paid.

Now, let's look at step by step.

this actual liquidity removal transaction
in this transaction