Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reserves above maximum not caught by swap trading function #442

Open
Alexangelj opened this issue Sep 6, 2023 · 1 comment
Open

Reserves above maximum not caught by swap trading function #442

Alexangelj opened this issue Sep 6, 2023 · 1 comment

Comments

@Alexangelj
Copy link
Contributor

Ref: https://github.com/primitivefinance/portfolio_simulations/blob/(bug-found)-invariant-pre-post-swap/bug_description.md

The Portfolio contracts calls validateSwap on the strategy contract and passes the adjusted reserves to the function. The adjusted reserves are the new reserves after the trade takes place without the fee. Therefore, the swap validation is checked on reserve values that could be less than what the actual reserve is because the fee could be large. This is not usually a problem, but it's a problem with the default strategy because any calls to the tradingFunction will now revert if using the Portfolio pool's reserves. This is because one of the reserves is at a bound (because of fees being added), while the other is not. This reverts now after making the fixes in https://github.com/primitivefinance/portfolio/tree/fix/trading-function-boundary

This is not as straightforward to fix because there's no place where we can run the additional verification the reserves have not eclipsed a bound, we would need to add some additional code to portfolio.

I am going to attempt to fix this on the temporary branch fix/arb-boundary-sims by not reverting, and instead overwriting the the reserves to the BOUND +/- 1 so the math ppf does not revert.

@Alexangelj
Copy link
Contributor Author

See 1d0df55 for attempted fix. Need to run the simulation with this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant