AMM price impact from trade size · Calculation guide

Estimate tokens received and execution price impact in a constant-product pool.

Calculation guide

Single swap with a proportional input fee. Benchmark the average fill against the pretrade reserve ratio. Report the curve impact separately from the all-in shortfall including fees.

output = y*(amount*(1-fee/100))/(x+amount*(1-fee/100)) · curve = 100*amount*(1-fee/100)/(x+amount*(1-fee/100)) · allin = 100*(1-output/(amount*y/x))

Inputs

Input-token reserve

Example entry 1000.

Output-token reserve

Example entry 2000.

Input tokens tendered

Example entry 100.

Input fee

Example entry 1 %. Allowed range 0 to 100.

Worked example

InputValue
Input-token reserve1,000
Output-token reserve2,000
Input tokens tendered100
Input fee1%
ResultValue
Output tokens received180.163785
Curve impact excluding fee9.008189%
All-in shortfall against spot9.918107%

Calculation steps

Output tokens received = ((Output-token reserve × (Input tokens tendered × (1 − (Input fee ÷ 100)))) ÷ (Input-token reserve + (Input tokens tendered × (1 − (Input fee ÷ 100)))))

((2,000 × (100 × (1 − (1 ÷ 100)))) ÷ (1,000 + (100 × (1 − (1 ÷ 100))))) = 180.163785

Curve impact excluding fee = (((100 × Input tokens tendered) × (1 − (Input fee ÷ 100))) ÷ (Input-token reserve + (Input tokens tendered × (1 − (Input fee ÷ 100)))))

(((100 × 100) × (1 − (1 ÷ 100))) ÷ (1,000 + (100 × (1 − (1 ÷ 100))))) = 9.008189%

All-in shortfall against spot = (100 × (1 − (Output tokens received ÷ ((Input tokens tendered × Output-token reserve) ÷ Input-token reserve))))

(100 × (1 − (180.163785 ÷ ((100 × 2,000) ÷ 1,000)))) = 9.918107%

How each input affects this example

Each row starts from the worked example and changes one input.

InputOriginal inputNew inputAffected resultOriginal resultNew result
Input-token reserve1,0001,100Output tokens received180.163785165.137615
Output-token reserve2,0002,200Output tokens received180.163785198.180164
Input tokens tendered100110Output tokens received180.163785196.410858
Input fee1%2%Output tokens received180.163785178.506375
AMM price impact from trade size →

Sources