Formula and accounting assumptions
Let g equal one minus the input swap fee, R be the initial input reserve and D the one-sided deposit. The balanced split solves g × swap^2 + (1 + g) × R × swap − D × R = 0. Its positive root determines the amount to swap. The model then computes acquired B, updated reserves and the smaller proportional deposit ratio available from the remaining A and acquired B. Pool ownership follows that proportional addition.
Worked hypothetical example
With 100 A and 100 B in a fee-free pool and a one-sided budget of 21 A, the balanced swap is ten A. It acquires approximately 9.090909 B and leaves eleven A for deposit. After the swap, reserves are 110 A and approximately 90.909091 B. Both deposit legs are exactly one tenth of those reserves, so the resulting ownership is 1 ÷ 11, approximately 9.090909%, with no modeled leftovers on either side.
Interpret the scenarios and limits
This is a full-range constant-product pool with input fees retained in the reserve. It does not apply directly to concentrated-liquidity positions or weighted pools. Minimum locked liquidity, protocol fee minting, integer rounding, transfer taxes, gas and intervening trades are omitted. Alternative split rows show whether unused inventory is A or B; maximizing a displayed token quantity is not the objective. The optimizer balances the modeled deposit ratio and does not predict fee income, profitability or the actual liquidity tokens minted by a contract.