balancer / balancer-v3-monorepo

GNU General Public License v3.0
24 stars 4 forks source link

Query and Actual batch swaps of boosted pools are different sometimes #738

Open joaobrunoah opened 6 days ago

joaobrunoah commented 6 days ago

Sometimes, a batch swap query in a boosted pool returns a slightly different result from the actual swap. It happens because the batch swap of a boosted pool is composed of three steps:

In the query mode, the first and third steps (wrap/unwrap) are only previews; we don't execute them, so the rate of the wrapped tokens doesn't change. However, the wrap/unwrap is executed in the actual operation so the total supply and total assets of the wrapped tokens change, and it introduces rounding issues in the order of 1 wei to the token rate. This rounding issue propagates to the boosted pool (2nd step) which uses a fixed 18 decimals rate, so it amplifies the error a bit for 18 decimal tokens.