This is the second article in our series "Predators in Pools: The Art and Math of JIT Liquidity." Here, we move from the theory of "snatching" to cold calculation: how an algorithm decides in 200 milliseconds whether it's worth jumping in.
If the first article was about "what it is," this one is about "what it costs." To prevent a JIT attack from turning into charity for miners/validators, the bot must solve a five-variable equation faster than a block gets mined.
1. Liquidity (L): The Main Variable
In Uniswap v3, liquidity isn’t just a sum of tokens, it’s the L factor that determines how much assets move when the price changes. Swap formula (invariant):

For a JIT bot, it’s critical to calculate what share of the total L in a given price range (tick) it should occupy.
Fee share formula (Fshare):
Fshare = Ljit / Lpool + Ljit
Where:
- Ljit — liquidity provided by the bot.
- Lpool — existing passive LP liquidity in the target tick.
Rule of thumb: To capture 95% of the fees, the bot’s liquidity must be 19 times the current pool liquidity in that range.
2. Calculating Swap Profit (Gross Profit)
The bot sees a user transaction of amount $S$ in the mempool. Knowing the pool’s fee tier ($\phi$, e.g., 0.05% or 0.3%), it calculates the total trade fee:

Expected gross profit for the bot (Pgross):

3. Accounting for "Gas Tax" (Operational Costs)
Unlike a passive LP who pays gas once for months of exposure, a JIT bot pays gas twice in a single block (or one expensive transaction with multiple calls).
Gas costs (Cgas):
mint(): ~150k–200k gas.decreaseLiquidity()+collect(): ~120k–180k gas.- Plus a priority fee for Flashbots to guarantee block inclusion.
On Ethereum mainnet, at 30 gwei gas, total costs can be $50–$150. On L2 (Arbitrum/Polygon), costs are tiny ($0.10–$0.50), but competition for micro-swaps is higher.
4. Calculating the Break-even Point
The attack only makes sense if:

Where Cslippage is the loss from removing liquidity (impermanent loss during a single swap), and Copportunity is the cost of capital (e.g., interest on a Flash Loan).
Little-known fact: Experienced bots account for "Shadow Slippage." When a bot injects huge liquidity, it makes the price "stiffer." If the user swap is large, the bot might inject less liquidity so the price moves more, planning to arbitrage it in the next block. But for pure JIT — more liquidity is better.
5. Practical Calculation Example (Mainnet)
- Pool: ETH/USDC (0.05%)
- User swap: $500,000.
- Current Lpool in tick: $2,000,000.
- Bot injects Ljit: $18,000,000.
- Total fees: $500,000 x 0.0005 = $250.
- Bot’s share: 18M / 18M + 2M = 90%.
- Bot revenue: $250 x 0.9 = $225.
- Gas cost: $120 (average conditions).
- Net profit: $225 - $120 = $105 per block.
Seems small? Top bots run 500–1000 such attacks daily. That’s $50,000–$100,000 net profit per day with almost zero market risk.
6. Technical Nuance: Choosing Tick Width
The bot never sets a wide range. The narrower the range (ticks), the higher the capital concentration and the higher $L$ for the same token amounts.
JIT standard: tickLower and tickUpper with a difference of 1 minimum step (e.g., 10 points for a 0.05% pool).
Liquidity calculation from token amounts (TypeScript/Ethers):
import { LiquidityAmounts } from '@uniswap/v3-sdk';
import { JSBI } from '@uniswap/sdk-core';
function calculateJitLiquidity(amount0, amount1, currentPrice, tickLower, tickUpper) {
const sqrtRatioX96 = encodePriceSqrt(currentPrice);
const sqrtRatioAX96 = TickMath.getSqrtRatioAtTick(tickLower);
const sqrtRatioBX96 = TickMath.getSqrtRatioAtTick(tickUpper);
return LiquidityAmounts.getLiquidityForAmounts(
sqrtRatioX96,
sqrtRatioAX96,
sqrtRatioBX96,
amount0,
amount1,
false
);
}
Article Summary
JIT math is a battle for efficiency. If you see a 1% fee pool suddenly drop in yield — check the mempool. Most likely, there’s a bot that calculated its $L$ to be 50 times more efficient than yours.
In the next article: We’ll move from formulas to hardware and code. We’ll explore the smart contract architecture executing these calculations on the fly and see why Rust has outpaced all other languages in this niche.
JIT Liquidity Mastery: The Complete Guide to MEV in Uniswap: Part 2 of 5