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

floor decimals on check expected balances #396

Merged
merged 2 commits into from
Oct 26, 2023

Conversation

silviutroscot
Copy link
Contributor

@silviutroscot silviutroscot commented Oct 26, 2023

Summary by CodeRabbit

  • Refactor: Enhanced the precision of internal calculations within the Kamino module. This change ensures more accurate balance computations, improving the reliability of the system.
  • New Feature: Added system logs for key balance calculations. This will aid in system monitoring and troubleshooting, enhancing the overall stability and maintainability of the application.

Please note, these changes are under-the-hood improvements and won't affect the user interface or user experience directly. However, they contribute to the overall performance and reliability of the system.

@coderabbitai
Copy link

coderabbitai bot commented Oct 26, 2023

Walkthrough

The changes introduced in this pull request primarily focus on enhancing the calculation and logging of expected token balances in the Kamino class. The calculation of expectedALamports and expectedBLamports has been refined, and additional console log statements have been added for better debugging and transparency.

Changes

File Path Summary
.../kamino-sdk/src/Kamino.ts Introduced intermediate variables for the calculation of expectedALamports and expectedBLamports. Added console log statements for these variables and for userTokenBalancesWithoutSolBalanace. Updated the CheckExpectedVaultsBalancesArgs object with the new values.

🐇

In the land of code, where the shadows lie,

A rabbit hopped, with a twinkle in its eye.

With each key press, a new world unfurls,

In the dance of brackets, and the swirl of curls.

A change here, a tweak there, the logic now clear,

Celebrate the changes, for the solution is near! 🎉


Tips

Chat with CodeRabbit Bot (@coderabbitai)

  • If you reply to a review comment from CodeRabbit, the bot will automatically respond.
  • To engage with CodeRabbit bot directly around the specific lines of code in the PR, mention @coderabbitai in your review comment
  • Note: Review comments are made on code diffs or files, not on the PR overview.
  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai help to get help.

Note: For conversation with the bot, please use the review comments on code diffs or files.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • The JSON schema for the configuration file is available here.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/coderabbit-overrides.json

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 0a5ccb7 and de25268.
Files selected for processing (1)
  • packages/kamino-sdk/src/Kamino.ts (2} hunks)
Files skipped from review due to trivial changes (1)
  • packages/kamino-sdk/src/Kamino.ts

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between de25268 and a1bce0e.
Files selected for processing (1)
  • packages/kamino-sdk/src/Kamino.ts (1} hunks)
Additional comments: 1
packages/kamino-sdk/src/Kamino.ts (1)
  • 2890-2895: The new approach to calculate expectedALamports and expectedBLamports by flooring the decimal values is a significant change. Ensure that this change doesn't introduce any rounding errors or inaccuracies in the CheckExpectedVaultsBalancesArgs object. Also, consider removing the console log statements after you finish debugging to maintain code cleanliness.
-    console.log('expectedALamportsDecimal ', expectedALamportsDecimal.toString());
-    console.log('expectedBLamportsDecimal ', expectedBLamportsDecimal.toString());
Committable suggestion (Beta)
    let expectedALamportsDecimal = collToLamportsDecimal(expectedABalance, strategyState.tokenAMintDecimals.toNumber());
    let expectedBLamportsDecimal = collToLamportsDecimal(expectedBBalance, strategyState.tokenBMintDecimals.toNumber());
    let expectedALamports = expectedALamportsDecimal.floor();
    let expectedBLamports = expectedBLamportsDecimal.floor();

    const args: CheckExpectedVaultsBalancesArgs = {
      tokenAAtaBalance: new BN(expectedALamports.toString()),

let expectedBLamports = collToLamportsDecimal(expectedBBalance, strategyState.tokenBMintDecimals.toNumber());
let expectedALamportsDecimal = collToLamportsDecimal(expectedABalance, strategyState.tokenAMintDecimals.toNumber());
let expectedBLamportsDecimal = collToLamportsDecimal(expectedBBalance, strategyState.tokenBMintDecimals.toNumber());
console.log('expectedALamportsDecimal ', expectedALamportsDecimal.toString());
Copy link
Collaborator

Choose a reason for hiding this comment

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

I would remove the logs from the SDK

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I thought to keep it for a few days just in case this keeps happening and then remove

Copy link
Collaborator

Choose a reason for hiding this comment

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

Fair enough

@silviutroscot silviutroscot merged commit 2da1372 into master Oct 26, 2023
3 checks passed
@silviutroscot silviutroscot deleted the silviu/fix-decimal-lamports branch October 26, 2023 13:32
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