---
# System prepended metadata

title: Swap calculation against two pairs

---

# Swap calculation against two pairs

The formula below is used to calculate the target swap amount for token A (ETH) to token B (CRV), in order to arrive at a precise LP amount to provide liquidity into token A / token C liquidity pair having no funds leftover. While some of the numbers may seem arbitrary, they are actually based on exchange fees applied to each swap so that trade actuals can be properly accounted for. 

### Definition of variables:
- B7 = pool1WantReserve 
- B13 = pool2Ratio
- B2 = haveAmount
- B6 = pool1HaveReserve  

  
### Formula

> =(SQRT(-1994 * B7 * B13 * (997 * B2 - 1000 * B6)
    + (B13^2) * (997 * B2 + 1000 * B6) ^2 
    + 994009 * (B7^2)
) + 997 * B2 * B13 - 997 * B7 - 1000 * B6 * B13) 
/ (1994 * B13)


