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

client-js: add JS helpers for interest bearing tokens' UIAmounts #53

Merged
merged 7 commits into from
Jan 13, 2025

Conversation

gitteri
Copy link
Contributor

@gitteri gitteri commented Dec 10, 2024

Similar to this PR in solana-program-library, this adds helper functions for interest bearing tokens for getting amountToUiAmount and uiAmountToAmount without needing to simulate a transaction.

  1. amountToUiAmountForMintWithoutSimulation - converts a number/bigint amount for a given mint at the current time to a UiAmount
  2. amountToUiAmountWithoutSimulation - converts a given number/bigint amount and detailed information about the mint's interest rates to a UiAmount
  3. uiAmountToAmountForMintWithoutSimulation- converts a given ui amount string for a given mint at the current time to amount
  4. uiAmountToAmountWithoutSimulation - converts a given ui amount string and detailed information about the mint's interest rates to amount

UiAmounts are provided with the token's decimals as its precision and truncated instead of rounded to avoid rounding issues.
Amounts are processed in the base unit of the token (if the token has 2 decimals 1.23 is represented as 123)

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.

Looks good to me overall! Mostly small things. @lorisleiva can you also take a quick look at the tests? I'm mostly interested in feedback on the test setup, and whether it aligns how we should write tests for these packages

clients/js/README.md Outdated Show resolved Hide resolved
clients/js/src/getAmountToUiAmount.ts Outdated Show resolved Hide resolved
Copy link
Contributor

Choose a reason for hiding this comment

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

Same here, I would call this file amountToUiAmount.test.ts

clients/js/src/getAmountToUiAmount.ts Outdated Show resolved Hide resolved
clients/js/src/getAmountToUiAmount.ts Outdated Show resolved Hide resolved
clients/js/src/getAmountToUiAmount.ts Outdated Show resolved Hide resolved
Copy link
Member

@lorisleiva lorisleiva left a comment

Choose a reason for hiding this comment

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

Thanks!

clients/js/src/getAmountToUiAmount.ts Outdated Show resolved Hide resolved
clients/js/package.json Outdated Show resolved Hide resolved
clients/js/src/getAmountToUiAmount.ts Outdated Show resolved Hide resolved
Copy link
Member

@lorisleiva lorisleiva left a comment

Choose a reason for hiding this comment

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

Thanks for making the changes!

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.

Looks good to me! Can you run pnpm format:fix to fix the formatting issue? You might also need to rebase to pick up the recent changes to CI

@joncinque joncinque enabled auto-merge (squash) January 13, 2025 23:07
@joncinque joncinque merged commit 769acd1 into solana-program:main Jan 13, 2025
19 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.

3 participants