Skip to content

[js-legacy] Fix program check in amountToUiAmount helper functions #444

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

Merged
merged 2 commits into from
May 19, 2025

Conversation

gitteri
Copy link
Contributor

@gitteri gitteri commented May 16, 2025

Update Program ID Matching Logic

Problem

Currently, the code uses strict equality (===) to compare program IDs with TOKEN_PROGRAM_ID and TOKEN_2022_PROGRAM_ID. This can lead to false negatives when comparing PublicKey instances, as they may have different object references even when representing the same underlying public key data.

Solution

Replace the strict equality checks with PublicKey.equals() method, which properly compares the underlying public key data rather than object references.

Changes

  • Updated program ID validation in amountToUiAmountForMintWithoutSimulation
  • Updated program ID validation in uiAmountToAmountForMintWithoutSimulation

Testing

  • Verified that the changes correctly identify both Token Program and Token-2022 Program IDs
  • Confirmed that the validation works with different PublicKey instances representing the same program ID

This PR fixes a bug in the amountToUiAmount helper functions for the scaled ui and interest bearing token extensions
Copy link
Contributor

@joncinque joncinque left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, right

Copy link
Contributor

@joncinque joncinque left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wait, hold on, this means that token_2022 and token will throw

@joncinque
Copy link
Contributor

joncinque commented May 16, 2025

The tests seem to agree that the code was fine before 😅

@gitteri
Copy link
Contributor Author

gitteri commented May 18, 2025

Sorry @joncinque you're absolutely right. I ran into this issue when trying to use this helper in an app and realized the actual issue is that the helper uses === equality check which doesn't work with the underlying BN data type.

Copy link
Contributor

@joncinque joncinque left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah ok, this makes sense, thanks!

@joncinque joncinque merged commit 66f31b9 into solana-program:main May 19, 2025
20 checks passed
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