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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

gitteri
Copy link
Contributor

@gitteri gitteri commented May 16, 2025

Fix Program ID Validation in amountToUiAmount helpers

Problem

The amountToUiAmountForMintWithoutSimulation and uiAmountToAmountForMintWithoutSimulation functions currently has an incorrect program ID validation check that prevents valid mints from being processed. The current check:

if (programId !== TOKEN_PROGRAM_ID && programId !== TOKEN_2022_PROGRAM_ID)

uses an AND (&&) operator, which means the program ID must be BOTH the token program ID AND the token 2022 program ID. This is logically impossible since a program can only have one owner, effectively blocking all valid mints from being processed.

Solution

Change the AND (&&) operator to an OR (||) operator to properly validate that the program ID is either the token program ID OR the token 2022 program ID:

if (programId !== TOKEN_PROGRAM_ID || programId !== TOKEN_2022_PROGRAM_ID)

Impact

This fix will allow the function to properly process mints owned by either the SPL Token program or the Token-2022 program, which is the intended behavior. These functions will now correctly handle:

  • Mints owned by the SPL Token program
  • Mints owned by the Token-2022 program
  • Properly reject mints owned by any other program

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 😅

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