You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fix: multipoolAutoswap was calculating output prices incorrectly. (#2166)
* fix: multipoolAutoswap was calculating output prices incorrectly.
It effectively had the two pools swapped. We didn't notice because all our tests had the two pools
at rough parity. While trying to make the staking contract work, I kept geting prices that were 2x
the input rather than half when I expected the opposite.
The tests were correspondingly broken. The tests called priceFromTargetOutput() to calculate
expected values, and consistently had the pools reversed in the call. The correct call is
`priceFromTargetOutput(deltaY, yPre, xPre, fee)`. Notice that the first two parameters are both in
`Y` units. The calls from the test have been corrected so the second parameter is the pool that
matches the requested output amount.
In the newly added test, the pool is set up with a ratio of 500 Moola to 1000 Central tokens. When
Alice asks the price for 300 Central, the price will now be 155. When she trades back, it takes
roughly twice the number of central tokens to purchase the moola she wants.
* refactor: Vault uses a priceAuthority to schedule liquidation
getPriceGivenAvailableInput and getPriceGivenRequiredOutput
added tests
renamed userSeat in addLiquidityActual() to zcfSeat. That cost me time!
* refactor: update getCurrentPrice
update prices that changed in tests.
* refactor: reduce four methods in pool for calculating prices to two
And use price improvements in multipoolAutoswap
* refactor: share & publish price calculations from getCurrentPrice.js
* fix: add a test, fix a bug, remove redundant code
* docs: add a description of the four methods for getting prices.
0 commit comments