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

Fix calculations in token-swap anchor example #330

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

dsctt
Copy link

@dsctt dsctt commented Nov 23, 2024

  • Fix liquidity ratio calculation in deposit and add tests
    Liquidity pool ratio was being calculated by multiplying token supplies instead of dividing causing incorrect amounts of attempted deposits and liquidity token mints. This bug wasn't caught by tests because the ratio is only used on deposits subsequent to the initial deposit and the tests previously only covered the initial deposit.

  • Fix invariant validation calculation in swap and add tests
    A suspected typo in the invariant calculation used for validation in swap_exact_tokens_for_tokens.rs would cause the program to fail even if the swap should otherwise be successful. This bug wasn't caught by tests because they did not cover the case when initial deposit contains amounts where a < b, which is the case when the failure occurs.

  • Anchor version
    Using anchor 0.30.0 gave me this error which is why this PR has 0.29.0.

**error****: custom attribute panicked**                                                                                   
  **-->** programs/token-swap/src/lib.rs:13:1                                                                            
   **|** **13** **|** #[program]                                                                                                      
   **|** **^^^^^^^^^^**                                                                                                      
   **|**                                                                                                                 
   **=** **help**: message: Safety checks failed: Failed to get program path

(Upgrading to anchor 0.30.1 also gives the same error but with a help message of **help**: message: compiler/fallback mismatch #949). I couldn't figure this out in a reasonable amount of time. If someone knows how to resolve this that would be great. If it's imperative that we use 0.30, I can try to spend more time on it.

@dsctt dsctt force-pushed the main branch 2 times, most recently from 80b60e7 to 772d816 Compare November 23, 2024 13:07
@nlgripto
Copy link

@buffalojoec 🫡

@nickfrosty nickfrosty requested a review from heyAyushh November 25, 2024 15:46
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.

2 participants