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

fix: ensures that DecCoin doesn't loose precision for very long numbers #194

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

stalniy
Copy link
Contributor

@stalniy stalniy commented Feb 27, 2025

Why

Current implementation relies on parseInt + devision which will loose precision for very long numbers

What

  1. Rewrites DecCoin encode/decode to relying on BigInt checks + string manipulation
  2. Adds more test cases to validate edge cases

@stalniy stalniy requested a review from a team as a code owner February 27, 2025 03:56
@stalniy stalniy force-pushed the fix/dec-coin-encoding branch 2 times, most recently from 582f255 to c87b9f1 Compare February 27, 2025 03:58
@stalniy stalniy force-pushed the fix/dec-coin-encoding branch from c87b9f1 to 38905dd Compare February 27, 2025 10:47
@stalniy stalniy force-pushed the fix/dec-coin-encoding branch from 9f1e13c to 557a9ea Compare February 27, 2025 12:06
@@ -41,6 +41,7 @@
]
},
"dependencies": {
"@cosmjs/math": "^0.33.0",
Copy link
Member

Choose a reason for hiding this comment

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

need to check if this version is compatible with sdk-47.
go implementation uses math package of version v1.3.0, which is not latest

import * as minimal from "protobufjs/minimal";
import { Reader } from "protobufjs/minimal";

import * as coin from "../../../../generated/cosmos/base/v1beta1/coin.original";
import { DecCoin } from "../../../../generated/cosmos/base/v1beta1/coin.original";

const originalEncode = coin.DecCoin.encode;
const PRECISION = 18;
Copy link
Member

Choose a reason for hiding this comment

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

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