curveresearch / curvesim

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

`exchange` gives incorrect result #220

Closed chanhosuh closed 1 year ago

chanhosuh commented 1 year ago

Version Information

$ python -m curvesim --version
curvesim 0.5.0.b1, CPython 3.10.0 on Darwin

What's your issue about?

>> import curvesim
>> pool = curvesim.pool.get("0x5426178799ee0a0181a89b4f57efddfab49941ec", env='staging')
>> pool.exchange(1, 0, 10**18)
(199111088072776543986652, 598819974073168473476)

this is the TricryptoINV pool, which holds USDC, ETH, INV (~$200k each), so 1 ETH will give you almost all the USDC in the pool

How can it be fixed?

No idea. Needs further investigation.

chanhosuh commented 1 year ago

Seems like the D in the pool snapshot is wrong (roughly 1/3rd the actual value). However, the "snapshot" isn't actually pulling the value of D from the subgraph but computing it itself (using stableswap logic). We should remove computational logic from the snapshot flow entirely to avoid these issues.

chanhosuh commented 1 year ago

After some discussion, seems like the reason we have the D computation as part of the snapshot is for creating balanced pools for sims. We can just do that explicitly in the get_sim_pool factory function. The snapshot itself should not have heavy computational logic in it. This is best left to the pool.