curveresearch / curvesim

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

Implement `remove_liquidity` for Curve pools #258

Open chanhosuh opened 1 year ago

chanhosuh commented 1 year ago

Simple Summary

remove_liquidity should be added to each type of Curve pool.

Motivation / Use-case

This is a common function on the vyper pools. While not needed for current sims, this would enhance the expected pythonic interaction with curve pools.

Detailed Summary

The basic implementation of remove_liquidity is the same for all Curve vyper contracts. Each LP token owns a proportional amount of each coin balance based on its proportion of the LP total supply.

There are some finicky details with rounding, and claiming fees (in the case of cryptoswap), but these aren't too bad; the 3Pool contract should be used as reference for regular stableswap/metapool and the tricrypto-ng as reference for cryptoswap. These are already in the codebase as test fixtures and the pythonic implementation should match results exactly.

As it may turn out there could be some issues (perhaps between 2 and 3 coin cryptoswap), these should be done in separate PRs to simplify review.

Backwards Compatibility

N/A