Skip to content

Commit 1f4de53

Browse files
fix: fix parse unit error when value is 1e format (#115)
# 🤖 Linear Closes PAR-XXX ## Description ## Checklist before requesting a review - [x] I have conducted a self-review of my code. - [x] I have conducted a QA. - [ ] If it is a core feature, I have included comprehensive tests. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **New Features** - Introduced a utility to consistently format numerical values without grouping, providing clearer, unambiguous number representations. - **Bug Fixes** - Improved the precision of numerical data in pricing and funds processing to ensure more reliable calculations and display. These changes enhance the consistency and accuracy of financial data presentation across the platform. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
2 parents 98655ec + d5b823b commit 1f4de53

File tree

5 files changed

+28
-7
lines changed

5 files changed

+28
-7
lines changed

packages/pricing/src/providers/coingecko.provider.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ export class CoingeckoProvider implements IPricingProvider {
123123
endTimestampMs = currentTimestamp as TimestampMs;
124124
}
125125

126-
const path = `/coins/${tokenId}/market_chart/range?vs_currency=usd&from=${startTimestampMs / 1000}&to=${endTimestampMs / 1000}&precision=full`;
126+
const path = `/coins/${tokenId}/market_chart/range?vs_currency=usd&from=${Math.floor(startTimestampMs / 1000)}&to=${Math.floor(endTimestampMs / 1000)}&precision=full`;
127127
try {
128128
const { data } = await this.axios.get<CoingeckoPriceChartData>(path);
129129
const closestEntry = data.prices.at(0);

packages/processors/src/helpers/utils.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,14 @@ export const getDateFromTimestamp = (timestamp: bigint): Date | null => {
2121
export const isMilliseconds = (timestamp: bigint): boolean => {
2222
return timestamp >= 10_000_000_000n;
2323
};
24+
25+
/**
26+
* Converts a number to a string with no grouping
27+
* @param number - The number to convert to a string
28+
* @returns The number as a string with no grouping
29+
*/
30+
export const toNumericString = (number: number): string => {
31+
return Number(number).toLocaleString("fullwide", {
32+
useGrouping: false,
33+
});
34+
};

packages/processors/src/processors/allo/handlers/poolMetadataUpdated.handler.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import type { ChainId, ProcessorEvent } from "@grants-stack-indexer/shared";
55
import { getToken } from "@grants-stack-indexer/shared";
66

77
import type { IEventHandler, ProcessorDependencies } from "../../../internal.js";
8-
import { getTokenAmountInUsd } from "../../../helpers/index.js";
8+
import { getTokenAmountInUsd, toNumericString } from "../../../helpers/index.js";
99
import { RoundMetadataSchema } from "../../../schemas/index.js";
1010

1111
type Dependencies = Pick<
@@ -49,7 +49,9 @@ export class PoolMetadataUpdatedHandler implements IEventHandler<"Allo", "PoolMe
4949

5050
if (parsedRoundMetadata.success && token) {
5151
matchAmount = parseUnits(
52-
parsedRoundMetadata.data.quadraticFundingConfig.matchingFundsAvailable.toString(),
52+
toNumericString(
53+
parsedRoundMetadata.data.quadraticFundingConfig.matchingFundsAvailable,
54+
),
5355
token.decimals,
5456
);
5557
matchAmountInUsd = (

packages/processors/src/processors/strategy/donationVotingMerkleDistributionDirectTransfer/dvmdDirectTransfer.handler.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,11 @@ import {
1212

1313
import type { ProcessorDependencies, StrategyTimings } from "../../../internal.js";
1414
import DonationVotingMerkleDistributionDirectTransferStrategy from "../../../abis/allo-v2/v1/DonationVotingMerkleDistributionDirectTransferStrategy.js";
15-
import { calculateAmountInUsd, getDateFromTimestamp } from "../../../helpers/index.js";
15+
import {
16+
calculateAmountInUsd,
17+
getDateFromTimestamp,
18+
toNumericString,
19+
} from "../../../helpers/index.js";
1620
import { TokenPriceNotFoundError, UnsupportedEventException } from "../../../internal.js";
1721
import {
1822
BaseDistributedHandler,
@@ -128,7 +132,7 @@ export class DVMDDirectTransferStrategyHandler extends BaseStrategyHandler {
128132
token: Token,
129133
blockTimestamp: TimestampMs,
130134
): Promise<{ matchAmount: bigint; matchAmountInUsd: string }> {
131-
const matchAmount = parseUnits(matchingFundsAvailable.toString(), token.decimals);
135+
const matchAmount = parseUnits(toNumericString(matchingFundsAvailable), token.decimals);
132136

133137
const matchAmountInUsd = await this.getTokenAmountInUsd(token, matchAmount, blockTimestamp);
134138

packages/processors/src/processors/strategy/easyRetroFunding/easyRetroFunding.handler.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,11 @@ import {
1111
} from "@grants-stack-indexer/shared";
1212

1313
import EasyRetroFundingStrategy from "../../../abis/allo-v2/v1/EasyRetroFundingStrategy.js";
14-
import { calculateAmountInUsd, getDateFromTimestamp } from "../../../helpers/index.js";
14+
import {
15+
calculateAmountInUsd,
16+
getDateFromTimestamp,
17+
toNumericString,
18+
} from "../../../helpers/index.js";
1519
import {
1620
ProcessorDependencies,
1721
StrategyTimings,
@@ -105,7 +109,7 @@ export class EasyRetroFundingStrategyHandler extends BaseStrategyHandler {
105109
token: Token,
106110
blockTimestamp: TimestampMs,
107111
): Promise<{ matchAmount: bigint; matchAmountInUsd: string }> {
108-
const matchAmount = parseUnits(matchingFundsAvailable.toString(), token.decimals);
112+
const matchAmount = parseUnits(toNumericString(matchingFundsAvailable), token.decimals);
109113

110114
const matchAmountInUsd = await this.getTokenAmountInUsd(token, matchAmount, blockTimestamp);
111115

0 commit comments

Comments
 (0)