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

Closed
wants to merge 0 commits into from

Conversation

dyodx
Copy link

@dyodx dyodx 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.

@dyodx dyodx force-pushed the main branch 3 times, most recently from 772d816 to f8415eb Compare November 23, 2024 13:15
@nlgripto
Copy link

@buffalojoec 🫡

@dyodx
Copy link
Author

dyodx commented Jan 8, 2025

oops. this was a while ago, i can redo this if you guys want the fix @heyAyushh

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