Skip to content

Conversation

@MrBlackGhostt
Copy link

This PR fixes two critical logic bugs in the deposit_liquidity instruction:

  1. Ratio Calculation Fix: The code was incorrectly multiplying pool amounts (pool_a * pool_b) instead of dividing (pool_a / pool_b) to determine the current pool ratio. This led to incorrect LP token calculations.

  2. Arbitrarily selected which input amount to use based on if pool_a > pool_b, which could cause transactions to fail even when users provided sufficient funds

    • Calculate optimal amount_a based on provided amount_b
    • If optimal amount_a fits within user's input, use it
    • Otherwise, calculate optimal amount_b based on provided amount_a
    • Guarantees deposits succeed using maximum possible liquidity within user's constraints

The deposit_liquidity instruction was incorrectly multiplying pool amounts
instead of dividing them to calculate the ratio between Pool Token A and
Pool Token B. This caused incorrect LP token minting calculations for subsequent
deposits.

This change fixes the logic to use division: Ratio = Pool A / Pool B.
@MrBlackGhostt
Copy link
Author

@aaronbassett

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant