balancer / balancer-v3-monorepo

GNU General Public License v3.0
37 stars 10 forks source link

Add guardrails for `invariantRatio` & improve rounding in `BasePoolMath` (unbalanced liquidity operations) #812

Closed jubeira closed 1 month ago

jubeira commented 1 month ago

Description

In the current state, we can't apply pool-specific guardrails for big unbalanced liquidity operations at the pool level for computeInvariant. BasePoolMath just computes the invariant several times and solves the result, but unless we apply system-wide constraints there's no way to get pool-specific constraints unless we add a new getter to the pools.

An alternative approach is to write the computations in BasePoolMath in terms of the ratio, allowing pools to implement their own constraints.

WIP for now; tests are not passing yet.

Type of change

Checklist:

Issue Resolution