curveresearch / curvesim

Simulates Curve Finance pools
MIT License
156 stars 32 forks source link

Disable _tweak_price for Estimating Liquidity Density? #227

Closed nagakingg closed 11 months ago

nagakingg commented 1 year ago

Estimating liquidity density requires comparing the prices before/after a small trade. However, for CryptoSwap pools, this becomes wrong in the rare cases where the small trade causes a pool rebalance.

I'm proposing to add an optional tweak_price = True kwarg to the SimCurveCryptoswap.trade() function, and the downstream functions exchange and _exchange.

I wanted to discuss this (or alternatives) because:

chanhosuh commented 1 year ago

I think rather than impact the rest of the codebase, it's better to just do something to the pool's state so there is no rebalance. This means the liquidity density function knows something about the pool (as it should) but nothing else needs to be aware.

For example, temporarily increasing allowed_extra_profit to infinity would block any price adjustment.

nagakingg commented 1 year ago

Awesome, very clever solution. I'll do something like this.

nagakingg commented 11 months ago

Closed by #285