Fix calculations in token-swap anchor example #330
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
(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.