Skip to content

Fix invariant check in token-swap swap function#524

Open
Zentex1337 wants to merge 1 commit intosolana-developers:mainfrom
Zentex1337:fix/issue-477-invariant-check
Open

Fix invariant check in token-swap swap function#524
Zentex1337 wants to merge 1 commit intosolana-developers:mainfrom
Zentex1337:fix/issue-477-invariant-check

Conversation

@Zentex1337
Copy link

Summary

  • Fixed the invariant check in swap_exact_tokens_for_tokens.rs at line 137
  • Changed pool_account_a.amount * pool_account_a.amount to pool_account_a.amount * pool_account_b.amount
  • This correctly verifies the constant product invariant (x * y = k) used in the CPAMM

Test plan

  • The change is straightforward and corrects an obvious typo
  • The invariant check should now properly compare against the product of both token amounts

Fixes #477

The invariant check at line 137 was incorrectly comparing against
pool_account_a.amount * pool_account_a.amount when it should be
pool_account_a.amount * pool_account_b.amount to properly verify
the constant product invariant (x * y = k).

Fixes solana-developers#477
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.

token-swap tiny but serious typing error.

1 participant